From: "Dan Kubb (dkubb)" Date: 2010-06-17T02:50:04+09:00 Subject: Re: datamapper blues > I've ranted about this elsewhere, so I'll keep this short, but I urge you to not be misled by the word "legacy." This thread was started by someone having problems using an ORM with a legacy schema, so that's what we've been discussing mostly. However, this problem can be more generally classified as an issue with controlling the mapping between an existing schema and ruby classes. > I've just started working on a brand new database project for a client, and I ended up using Sequel instead of Datamapper or ActiveRecord because it looked like it would be much easier to support the full PostgreSQL feature set with Sequel. Sequel is a fine ORM, and is very well designed. If it meets your needs, then I think that's great. It's probably better if you want to work at a layer closer to the database, and work with SQL more directly. You're also correct that ActiveRecord probably won't support arbitrary schemas. However DataMapper should be able to map to most existing schemas, since the table name and column names can be overridden as needed. It also provides a default naming convention layer, but you can even override that and provide your own code. > While it's very clear that, at least among Ruby fans, my 'database first' approach isn't very common, I do know that I'm not the only person who designs this way. It probably isn't very common since ActiveRecord is probably used by 10x more people than DataMapper or Sequel. > I was really really surprised when I first realized that none of the major ORMs I looked at were clever enough to figure out that, if the DB engine calls a column a Primary Key, then, um, it's the Primary Key. DataMapper makes no assumptions about what should be the PK or not. It trusts whatever you tell it about the mapping/types and acts accordingly. You can even specify different names for the columns in ruby as in the DB, eg: property :table_id, Serial, :field => 'tableID' If this wasn't clear from the DataMapper documentation, that's our failing not yours. We need to start documenting how the mapping works better, and show people how most schemas can be handled, and you can use specific naming conventions in your ruby code and schema while maintaining loose coupling between them. -- Dan