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.
DataMapper 0.9 also is not tied just to RDBMS, it is well abstracted persistence framework.
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.
yup, you can persist to a bunch of other places outside of the usual RDBMs (sqlite, mysql, postgres).
One of the spiffiest one’s I’ve seen so far is Wycat’s IMAP adapter (http://github.com/wycats/dm-adapters/tree/master/imap), which would make calls direct to a mail server for persistence.
Leave a comment