Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 certainly be writing to it.

like image 613
Mark Richman Avatar asked Nov 13 '10 21:11

Mark Richman


2 Answers

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.

like image 184
snusnu Avatar answered Sep 28 '22 05:09

snusnu


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).

like image 38
postmodern Avatar answered Sep 28 '22 05:09

postmodern