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
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.
On Mar 27, 4:02 am, Tim P. email@example.com