Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataMapper vs ActiveRecord in Rails 3 [closed]

I am curious on what you guys think about DataMapper and what benefits does it bring over the new and improved ActiveRecord in Rails 3.

I appreciate your opinions.

like image 952
Ivo Sabev Avatar asked Jan 10 '11 05:01

Ivo Sabev


2 Answers

I prefer DM to AR. I feel DM is actually an ORM whereas AR is just a wrapper around SQL. DM makes is very easy to switch between data stores. Query syntax of DM is much more homogeneous etc. SEL (strategic eager load) also makes DM look more like an object store than AR.

Moreover, DM classes define properties up front and it makes the code much more readable. I have never missed migrations after coming to DM world. (even though you may have them if you really wish). With rails 3, I am almost exclusively using DM.

like image 55
piyush Avatar answered Oct 17 '22 23:10

piyush


I used Active Record in Rails 2 and DataMapper in Merb and Rails 3—I now use DM/Rails 3 daily. I've read up on AR3 but only used it in one small project (an in-house app.)

I've found the only difference I really care about is DM's strategic eager loading. It rarely does what one would hope and what it does, right and wrong, it does with FM.

With explicit eager loading in AR, there's no question what should be occurring: it says what it does and (usually) does what it says.

While "automatic" eager loading sounds good, I find it has two negative results for me:

  1. not insignificant amounts of time spent searching for sources of excessive querying
  2. code littered with pseudo eager loading hacks where relations are materialized and discarded just to prime them and the identity map in ways that occasionally don't "stick" and are never self-documenting.

Otherwise, I find AR and DM to be the same beasts with different spots. Unlike say, Sequel.

like image 30
Yuri Gadow Avatar answered Oct 18 '22 00:10

Yuri Gadow