The main difference is that in DataMapper the model is defined in the ruby class itself:
class Post include DataMapper::Resource property :id, Serial property :title, String property :body, Text property :created_at, DateTime end
In ActiveRecord, the class is basically an empty class, and the HR service scans the database. This means that you either need a predefined database or use something like migration to generate the schema, which is why the data model is separate from the ORM.
DataMapper.auto_migrate!
will generate a circuit for you.
ActiveRecord is different in this respect:
class Post < ActiveRecord::Base end
There is no need for transfers in DataMapper, as automation can generate a schema or view the differences between the model and the database and migrate for you. There is also support for manual migration, which you can use for non-trivial cases.
In addition, DataMapper is a much more “ruby” syntax approach, and features such as lazy loading when binding conditions are met (for example, ActiveRecord in Rails 3) start from the very beginning.
Datamapper also has a function that each entry in the database maps to a single ruby object, which is not true for ActiveRecord. Therefore, if you know that the database records are the same, you know that two references to the ruby object will point to the same object.
On the flip side, while Rails 3 may promise you exchangeable frameworks, the Datamapper railtie (dm-rails) is not ready for production, and many functions may not work.
See page for details.
duncan
source share