28

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.

Ivo Sabev
  • 5,066
  • 1
  • 24
  • 38

2 Answers2

11

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.

piyush
  • 573
  • 2
  • 23
  • Don't you guys find the cost of implementing DM too high. In terms of all those gems you might want to use, but they assume you have AR and then you need to hack the gems and so on. For example Devise is a good user auth gem, but it wants AR and although there is already third party devise-dm gem it is a third party and who knows when they will stop support it or when Devise will be updated without the wrapper being updated. This is just and example situation. – Ivo Sabev Jan 13 '11 at 05:36
  • 3
    devise-dm works fine. DM also have quite a lot of third party gems. With time, as DM matures, these issues will fade away. – piyush Jan 13 '11 at 11:29
  • i have yet to see an activerecord that can handle Class Table Inheritance, whereas datamappers seem to . can anyone confirm this? thx – Neil McGuigan Apr 17 '12 at 05:19
2

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.

Yuri Gadow
  • 1,774
  • 2
  • 15
  • 26
  • Do you use sequel? If not, why not? – gucki Apr 22 '11 at 19:59
  • 1
    @gucki I used it for a project over a year ago but switched to DM since. I really don't recall the problems we were having too well, I *think* it may have been problems dealing with relationships before persisting, but I wouldn't like to swear to it. I do remember there was nothing wrong with Sequel per se, e.g., bugs, and the problems were design-impedance mismatches. If I were starting a new project today, I'd certainly review Sequel again as I'm very sick of the ORM lie these days. – Yuri Gadow Apr 22 '11 at 23:03