Lessons learned on my first date with DataMapper
Today I started playing around with DataMapper, an up-and-coming ORM that’s popular among the Merb/Sinatra kids, and one that’s making its way into Rails 3 as an alternative to ActiveRecord. Here are some notes from day one:
Different Database Column Defaults: The default String size is 50 characters, unlike ActiveRecord which defaults to 255 (for MySQL, anyway)
Strategic Eager Loading: At first I was dismayed to find there’s no :include option for nesting associations in a query. Then I realized it’s not necessary! DataMapper will only issue the very bare minimums of queries to your data-store that it needs to. Read more about it here.
Serialization: DataMapper is intended to have a lean and minimalistic core, which provides the minimum necessary features for an ORM. In order to successfully convert an array of objects to JSON (or XML or CSV or YAML), you’ll need to get the dm-more gem and drop a require 'dm-serializer' in your app.
Scopes: As with eager loading, DataMapper is smart about reducing the number of queries it makes. Check this out:
So far, I’m finding DataMapper to be smart and intuitive. Here’s to day two..