Active Record vs Data Mapper

Look at rBatis, possibly? https://rubyforge.org/projects/rbatis/

rBatis has given me an incredible appreciation for AR!

In most cases, you'll find it very similar to hibernate. Yes, with rBatis you're buying more configuration time for yourself. It's a bit more of a purist ORM tool in that respect. With rBatis you can completely decouple your domain from the relational DB because of the configuration (mapping) that you provide in the domain class. If I had a complaint about rBatis it's that it doesn't quite drive the ORM concept far enough since the mapping actually resides in the domain class.

AR is a different approach all together. The intention of AR is essentially to wrap an object around a DB row. Practically speaking, though, I have not seen a lot of hibernate/iBatis solutions that really push far from this 1:1 correspondence. If you can settle the lost flexibility in your own mind, you'll gain a great deal of productivity by skipping the configuration.

Just curious -- what types of complex domain logic do you reckon would be beyond the capability of AR?

HTH, AndyV

I have an extraordinarily normalized database, which I'm having a lot of trouble modeling with AR, because there simply cannot be a 1:1 correspondence between an object and a DB row. I have hacked a solution that works fair, but is not perfect.

Thanks for the rBatis link, I'm going to check it out! I hadn't heard of it before, and it might be just what I need for modeling one particular part of our database.

In our database, we have 3 normalized tables for product configurations. One table, the config_items table, holds the value of the configuration item as a varchar, and a foreign key to our config_types table. The config_types table stores a description of the config_item, the mysql datatype of the config_item as a varchar, for instance "tinyint", and a foreign key to the config_families table, which simply stores a varchar name for the configuration family (or category).

For instance, one config_item's value might be "Windows XP", which is linked to a config_type with the description "operating system" and data type "varchar", which is then linked to a "software" config_family.

I've got an AR model named SoftwareConfigurations, which will extract all of the config_items and related config_types who are linked to a config_family of "software". When the SofwareConfigurations class is defined, I build new AR::ConnectionAdapters:Columns for each config_type, using it to automatically cast based on the datatype string stored in config_types. This way, I can say something like software_config.operating_system, and it would return back "Windows XP" as a string. It works, but I'm not sure how robust it will be. And frankly, something like this, really ISN'T an ActiveRecord, IMHO. Maybe rBatis will be just the ticket.