Active Record vs Data Mapper

Hey guys

Ive been doing some backgronud reading on the whole ORM scenario as i
was intersted in where AR actually came from and i can obviously see
what it was that AR has developed in the way that it has:

  • ease of use
  • maintanible
  • lots of functionality

and lots more stuff. But i was wondernig what happens when people want a
more complex domain model than the one that AR faciliates? are there any
options out there already for other types of ORM within ruby? Ive looked
into Og, but i cant see that it is particularly clean to use on first
glance.

I guess my question is this:

How are people using AR with complex domain logic, and if they are using
somthing other than AR to do it, what is it?

Cheers

Tim

On 3/26/07, Tim P. [email protected] wrote:

and lots more stuff. But i was wondernig what happens when people want a
more complex domain model than the one that AR faciliates? are there any
options out there already for other types of ORM within ruby? Ive looked
into Og, but i cant see that it is particularly clean to use on first
glance.

I guess my question is this:

How are people using AR with complex domain logic, and if they are using
somthing other than AR to do it, what is it?

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


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

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

I did see that, I had a poke around in the RDoc, but it seemed to use a
lot of configuration? Has anyone actually used RBatis enough to comment
on what it works like? I am aware of iBatis from java, but we always
used hibernate so im not sure how it compares?

Cheers

Tim

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

On Mar 26, 5:21 pm, Tim P. [email protected]

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

Nothing in particular, i just wanted to start a conversation about it as
i think its facinating. I read an interesting post on one of the prag
prog blogs the other day where dave i think it was, was talking about
wrapping AR models up in presentation classes to keep the domain logic
seperate from AR - sounded like another layer on of abstraction on some
instances of AR

Have you ever heard of this?

Tim

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.

On Mar 27, 4:02 am, Tim P. [email protected]