5

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.

Mark Richman
  • 28,948
  • 25
  • 99
  • 159

2 Answers2

12

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.

snusnu
  • 481
  • 3
  • 6
5

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

postmodern
  • 51
  • 1
  • 1
    Does any of this work with datetime_select? For example, I am trying to update a datetime field and it fails because of this: "published_at(1i)"=>"2010", "published_at(2i)"=>"11", "published_at(3i)"=>"14", "published_at(4i)"=>"07", "published_at(5i)"=>"59" – Mark Richman Nov 15 '10 at 22:14