Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use DataMapper instead of ActiveRecord [closed]

DataMapper idea is definitely better than ActiveRecord. It has one API for a variety of data stores, including RDBMS and NoSQL stores. DataMapper is much smarter then ActiveRecord. It has "Strategic Eager Loading". This feature single-handedly wipes out the "N+1 Query Problem". Additionally it allows lazy-loading of heavy fields like Text property. DataMapper allows you to create and search for any complex object graph simply by providing a nested hash of conditions. ActiveRecods is unsuitable to be used for associations in production. include method is ugly and unconfigurable. In October 2010 Josh Symonds makes a patch for this method to allow fields to be excluded from eager loaded. But that path was ignored and today in rails3 we have same ugly include method.

Even in Rails3 with brilliant AREL, ActiveRecord is far from the best orm for rails. You may say "wow, that new gem metawhere allows to write nice code like Article.where(:title.matches => 'Hello%', :created_at.gt => 3.days.ago)". But wait... DataMapper supports this out of a box! Maybe instead of modifying ActiveRecord to looks like DataMapper better is to extend and support better orm? More details of DataMapper can be found at http://datamapper.org/.

I think, that rails in later releases should allow us to select which orm to use, like now it allows a database selection. Even it will has only one option "ActiveRecord", people will search for available alternatives. When I was starting to learn rails, I thought that there is support only for ActiveRecord. And later I did not even try to look for something else.

Why I am writing all this stuff? I think, that we need to pay more attention to this nice ORM. If you are developer of some popular or not so popular gem, think about adding support of DataMapper. DataMapper community should write some migration guides from ActiveRecord or another ORM and keep documentation uptodate and your may help them. As for me, DataMapper community needs more people and you may be one of them. The only disadvantage of this ORM is lack of documentation and you may help.

So what do you think about that?

like image 852
Alexander Paramonov Avatar asked Mar 18 '11 11:03

Alexander Paramonov


1 Answers

Rails 3 allows you to use Datamapper, just not by default. It you do want to use datamapper with rails 3. Just do this

    rails new project_name -m http://datamapper.org/templates/rails.rb

Rails allows you to select, you can even use the --skip-active-record option. :) ( May not be straightforward but its there.

And yeah, Datamapper is awesome. :)

like image 200
Rishav Rastogi Avatar answered Sep 25 '22 13:09

Rishav Rastogi