DataMapper: A Better ORM for Ruby

One of the things that’s always irritated my about rails’ ActiveRecord framework is the way that the domain model lives in the database.Don’t get me wrong: it’s very clever, and a great showcase for ruby’s metaprogramming features, which will blow average C# / Java mind the mind when they first see it.

In rails, you build a database of your domain model, and create empty classes with the names of the domain entities (conventionally the singular of a database table name) which inherit from ActiveRecord. ActiveRecord then looks at your database, and using the magic of metaprogramming, hydrates your object with a bunch of properties that map to the database fields.

But I prefer to write my models in the code, and if you do too, you might want to take a look at DataMapper.

Published by Matt

I write software, and love learning how to do it even better.

Join the Conversation

3 Comments

  1. That’s really interesting. So you could still use it if you just wanted to persist to flat files, for example?

    Sounds like I need to dig a bit deeper.

Leave a comment

Your email address will not be published. Required fields are marked *