Skip to content

Instantly share code, notes, and snippets.

@owenthereal
Created September 27, 2011 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenthereal/1244351 to your computer and use it in GitHub Desktop.
Save owenthereal/1244351 to your computer and use it in GitHub Desktop.
Comparison between the DataMapper gem and the ActiveRecord gem
class Store < ActiveRecord::Base
has_many :products
belongs_to :user
validates_presence_of :name
end
> Store.create(:name => "Amazon")
> Store.where(:name => "Amazon")
class Store
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :products
belongs_to :user
validates_presence_of :name
end
> Store.create(:name => "Apple")
> Store.all(:name => "Apple")
@owenthereal
Copy link
Author

As you may see, the datamapper gem and the activerecord gem are both an implementation of the Active Record pattern (http://martinfowler.com/eaaCatalog/activeRecord.html).

@dkubb
Copy link

dkubb commented Oct 10, 2011

@jingweno you probably want a comma after the n on line 7.

@owenthereal
Copy link
Author

Thanks @dukbb, I have fixed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment