# ActiveRecord Multiple Inheritance solution

**URL:** <https://www.ruby-forum.com/t/activerecord-multiple-inheritance-solution/83514>\
**Category:** Rails\
**Created:** [January 26, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/activerecord-multiple-inheritance-solution/83514 "2007-01-26T21:30:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@brianj](https://www.ruby-forum.com/u/brianj)\
**Post date:** [January 26, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/activerecord-multiple-inheritance-solution/83514/1 "2007-01-26T21:30:59Z")

</div>

Hello,

I am stuck in an environment where there is a massive Oracle database  
model in place which cannot be changed, is accessed by large java  
systems, and have been tasked with connecting to it all with Ruby on  
Rails. The biggest hurdle has been the fact that we use a multiple  
table inheritance model (per class hierarchy), which Rails definitely  
doesn’t support out of the box. I’ve looked around for many solutions,  
and spent the last week or two finally trying to roll my own.

The following is what I have created, and I would like to contribute it  
to the community. Any feedback is welcome.

The project is stored in SVN here: [http://svn.mojobojo.com/armi](http://svn.mojobojo.com/armi)

It lacks unit tests, and only has inline documentation. Hopefully I  
can get around to that sometime, and I apologize in advance for the  
lack thereof.

I’ve tested it against Oracle and MySQL, but not PostreSQL.  
Unfortunately I don’t think SQLite will work, since it has no way to do  
sequences as far as I can tell.

The biggest drawback is the number of queries performed, and I can’t  
think of a way around that. The price of flattening multiple tables  
into a single object I suppose.

Enjoy.

Brian J.  
[http://www.mojobojo.com](http://www.mojobojo.com)

---

<div class="post-metadata">

**Author:** ![brianj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@brianj](https://www.ruby-forum.com/u/brianj)\
**Post date:** [January 26, 2007, 9:40pm UTC](https://www.ruby-forum.com/t/activerecord-multiple-inheritance-solution/83514/2 "2007-01-26T21:40:47Z")

</div>

could you show a sample of your DB that is causing this problem?

---

<div class="post-metadata">

**Author:** ![brianj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@brianj](https://www.ruby-forum.com/u/brianj)\
**Post date:** [January 27, 2007, 6:54am UTC](https://www.ruby-forum.com/t/activerecord-multiple-inheritance-solution/83514/3 "2007-01-27T06:54:54Z")

</div>

On Jan 26, 3:00 pm, “Brian J.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> there are already huge systems in place using a different and widely  
> I built this because I am in an environment where changing the db model  
> is _not an option_.
> 
> Brian

Did you consider using any of Dr. Nic’s Models?

Jason

---

<div class="post-metadata">

**Author:** ![brianj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@brianj](https://www.ruby-forum.com/u/brianj)\
**Post date:** [January 26, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/activerecord-multiple-inheritance-solution/83514/4 "2007-01-26T22:01:05Z")

</div>

On Jan 26, 11:40 am, Keynan P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> could you show a sample of your DB that is causing this problem?
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

We use what is known as “per class inheritance” here, which means a 1  
object to many table relationship. ActiveRecord is closest to a “per  
concrete class” model, which is a 1 object to 1 table relationship.  
There is no way to use ActiveRecord’s modeling convention, because  
there are already huge systems in place using a different and widely  
used convention.

The following is a good article explaining the three standard models  
that are used (not really sure what xcalia is, but good article):

> **[DropCatch.com](https://www.DropCatch.com/domain/xcalia.com)**
>
> DropCatch.com helps you secure expiring domain names.

Sorry about not going into specific detail, but I feel that this helps  
clarify the point.

I built this because I am in an environment where changing the db model  
is _not an option_.

Brian
