Rails 3: ActiveRecord vs. DataMapper (vs. ???) for Legacy MySQL Databases
Which ORM is best to use with a new Rails 3 app against a legacy MySQL 5.1 database? I do not expect to ever run a migration against this database (though the schema may change from time to time), but I will certainl开发者_开发问答y be writing to it.
I may be biased towards DataMapper, but I think DM is generally a good option for integrating with legacy databases.
DM allows you to map meaningful model and property names to cryptic legacy table and column naming conventions. It allows you to do so either on a per model/property, or an app wide basis.
DM supports lazy properties, that will only be fetched when actually accessed.
DM has seamless support for composite primary keys.
DM only cares about the properties (columns) you explicitly declare in your models. Other columns will never be touched or read.
DM works nice with foreign key constraints in your database and with the help of dm-constraints it also supports creating them.
There's some documentation on http://datamapper.org/docs/legacy too.
There is also the dm-types-legacy library (https://github.com/postmodern/dm-types-legacy) which provides common DM Types for mapping in oddly formatted data (Numeric IP Addresses, HTML/URI encoded text, Date/Time strings).
精彩评论