# Active Record vs Data Mapper

**URL:** <https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226>\
**Category:** Rails\
**Created:** [March 26, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226 "2007-03-26T22:07:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [March 26, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226/1 "2007-03-26T22:07:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [March 26, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226/2 "2007-03-26T23:18:09Z")

</div>

On 3/26/07, Tim P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](https://rubyforge.org/projects/rbatis/)

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [March 26, 2007, 11:21pm UTC](https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226/3 "2007-03-26T23:21:07Z")

</div>

> Look at rBatis, possibly? [https://rubyforge.org/projects/rbatis/](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

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [March 27, 2007, 6:00am UTC](https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226/4 "2007-03-27T06:00:40Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [March 27, 2007, 10:02am UTC](https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226/5 "2007-03-27T10:02:07Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [March 27, 2007, 3:52pm UTC](https://www.ruby-forum.com/t/active-record-vs-data-mapper/90226/6 "2007-03-27T15:52:31Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
