DataMapper, an Alternative to ActiveRecord
Published: November 13th, 2007If you haven’t heard of DataMapper yet, this would be perfect time to learn what it is. Let’s just say that ActiveRecord has a contender in the ring.
Have you heard of DataMapper yet? I just got notice of it today thanks to RubyInside. It’s an aspiring Ruby Object-Relational Mapper. The potential of this project looks really interesting; I especially like the “Eager Loading”:
zoos = Zoo.all first = zoos.first first.exhibits # Loads the exhibits for all the Zoo objects in the zoos variable.
Looks great eh? Check out their philosophy:
We like to call it “performant by default”. This feature single-handedly wipes out the “N+1 Query Problem”. No need to specify an include option in your finders.
I’m already in love.
No Migrations!
I also love the way they handle columns in a table. There are no migrations, no schema.rb, your database tables reflect what’s in the model. Here’s an example:
class Fruit < DataMapper::Base set_table_name 'frt' property :name, :string, :column => 'col2' end
I really like this philosophy for database development a lot better. Does anyone else dislike the way ActiveRecord1 handles database progression? I don’t really think it makes any sense, version control can easily do the task at hand.
Check it Out!
There’s really just so many great things about this project, there’s tons of potential brewing here. If you haven’t seen it yet, what are you waiting for?
- ActiveRecord is an object-relation mapping library mainly used for the Ruby on Rails framework: http://ar.rubyonrails.com/ [↩]

Hey, thanks! DataMapper looks great. I’m going to try it out. Loving your blog design btw
Thanks for the compliment! I’m really loving DataMapper myself. I think this is going to get quite a bit of adoption. I can really see it being put into other projects like Sinatra etc.
My interest is quite piqued by DataMapper too. It’ll be a very interesting library to watch over the next while.
On an unrelated note, you might want to increase the size of your monospaced fonts. They’re _really_ tiny in Safari.
Hm, yeah, there are a couple bugs in Safari, like the size of the shadow to the box. I’m in Safari right now, and I can’t see any font that is too small. What resolution are you on?
Looks almost exactly like Og (the ORM part of Ruby’s Nitro Web framework), especially in how the model drives the database.
I’m just about to try to add an “audit” filter to my as-yet-unreleased Rails app. This would report (to another database table) changes made to model objects, by whom, and specifically what columns changed, showing both the old and new values. (I’m spoiled: I’m replacing a pile of Perl code I wrote some years ago, and it did this. My users will at least ask about any functional regression, here.)
It looks like DataMapper might make this easier than ActiveRecord. But I’m _this close_ to having something up and running, after pussy-footing around with this for almost a year, and I’m reluctant to tear out a bunch of stuff and start anything over, just to get auditing the way I want it.
I could use some encouragement, specifically around not having to replace all my controller code (which is, alas, not very small or DRY) and the model validations I’ve got.
Or I could just say “this person added/updated this object”, possibly dumping all the values after save(), and leave it at that. But: Ick. Or read in the old object again (inside a transaction?) and do the comparison myself. But: *sigh*
Ready. Set. Go.
In terms of the formatting, you're allowed to use markdown, textile, or basic html; it's truly up to you -- what strikes your fancy?
You don't have to worry about your e-mail address being sold to a russian-spam-mafia. I'm only going to use it for my own weird needs; like asking you out for a date on a lonely night of coding.