DataMapper

Ruby's DataMapper 101

It's been a while and lately I've been playing again with Merb so I figured I'll post about DataMapper. DataMapper is an ORM for Ruby which most Merb users prefer because of its simplicity and neat features.

Before we can start playing with it, you can install it using the following command:

sudo gem install dm-core

Also, for the purpose of this tutorial we're going to install the sqlite database driver:

ORM

In my old days of Codeigniter, I never really did actually use an ORM and with all these Ruby stuff on my mind I went ahead looking if they have one (which I'm pretty sure of).

Basically what an ORM is that it turns your table into an object and you interact with it just like a regular object. Under the hood, DataMapper inspects the table's fields, primary keys and relationship and map this into your model's properties.

Syndicate content