# Class-table inheritance in ActiveRecord

**URL:** <https://www.ruby-forum.com/t/class-table-inheritance-in-activerecord/75118>\
**Category:** Rails\
**Created:** [November 7, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/class-table-inheritance-in-activerecord/75118 "2006-11-07T16:58:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@Ashley\_M](https://www.ruby-forum.com/u/Ashley_M)\
**Post date:** [November 7, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/class-table-inheritance-in-activerecord/75118/1 "2006-11-07T16:58:23Z")

</div>

Hi people

I’ve just submitted a patch that adds CTI to ActiveRecord. It’s not  
quite done yet - some stuff is untested, and associations (probably)  
don’t work with CTI classes. But you can read and write CTI records  
with no special syntax (it looks just like STI).

I’ve posted more details on my company’s blog here: http://  
[pdcm.codeweavers.net/2006/11/7/class-table-inheritance-in-activerecord](http://pdcm.codeweavers.net/2006/11/7/class-table-inheritance-in-activerecord)  
And you can download the patch from the Rails trac: http://  
[dev.rubyonrails.org/ticket/6566](http://dev.rubyonrails.org/ticket/6566)

The patch is quite large - it was a lot trickier to make it work than  
I thought at first because ActiveRecord has a few assumptions that  
only hold under STI. I’ve avoided nasty hacks but it still took some  
voodoo meta-programming to preserve the existing functionality.

Class-table inheritance is one of the big feature we want at my  
company before we start any big Rails apps. If anyone would like to  
use it in their own projects don’t wait to let me know 🙂 I’m hoping  
I can finish it off in a week or two. It’s hard to gauge the demand  
for CTI because not many people have attempted it so far.

Ashley

---

<div class="post-metadata">

**Author:** ![Ashley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@Ashley\_M](https://www.ruby-forum.com/u/Ashley_M)\
**Post date:** [November 7, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/class-table-inheritance-in-activerecord/75118/2 "2006-11-07T19:39:37Z")

</div>

On 7-Nov-06, at 10:55 AM, Ashley M. wrote:

> Hi people
> 
> I’ve just submitted a patch that adds CTI to ActiveRecord. It’s not  
> quite done yet - some stuff is untested, and associations (probably)  
> don’t work with CTI classes. But you can read and write CTI records  
> with no special syntax (it looks just like STI).

very exciting Ashley!

I have a project coming around the bend where this will be very useful.

thank you.  
Jodi

---

<div class="post-metadata">

**Author:** ![Ashley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@Ashley\_M](https://www.ruby-forum.com/u/Ashley_M)\
**Post date:** [November 8, 2006, 1:08pm UTC](https://www.ruby-forum.com/t/class-table-inheritance-in-activerecord/75118/3 "2006-11-08T13:08:49Z")

</div>

On 7 Nov 2006, at 18:38, Jodi S. wrote:

> I have a project coming around the bend where this will be very  
> useful.
> 
> thank you.  
> Jodi

Cool. I was hoping it would be useful to other people. There’s  
still a fair bit to do though, but I’m hoping to have it finished  
completely in 2-3 weeks.

If anyone from the core team is watching, does this look like  
something that could make it into the ActiveRecord core? The patch  
is pretty hefty, and there’s no way it could be maintained as a plug-  
in. If so, I could do with discussing the rest of the tests before I  
do any more work, as it’s quite a fundamental change to the way  
ActiveRecord maps objects to tables.

I can’t tell you how much I’d love this to be in 1.2 🙂

Ashley

---

<div class="post-metadata">

**Author:** ![Ashley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@Ashley\_M](https://www.ruby-forum.com/u/Ashley_M)\
**Post date:** [May 7, 2007, 12:29am UTC](https://www.ruby-forum.com/t/class-table-inheritance-in-activerecord/75118/4 "2007-05-07T00:29:26Z")

</div>

Hi Ashley

Thanks for you post, I’m exactly looking for a Class Table Inheritance  
pattern for Rails.

I see now (after 6 months) your patch, and I wondering if you are still  
working on it.

Please, can you give me some update on your research?

Thanks
