# Inheriting model detail

**URL:** <https://www.ruby-forum.com/t/inheriting-model-detail/148981>\
**Category:** Rails\
**Created:** [September 18, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/inheriting-model-detail/148981 "2008-09-18T21:43:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonas\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jonas\_s](https://www.ruby-forum.com/u/jonas_s)\
**Post date:** [September 18, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/inheriting-model-detail/148981/1 "2008-09-18T21:43:55Z")

</div>

Hello,

I want to create models with child models.  
As an example, one model Event and submodels OneTimeEvent and  
RecurringEvent.  
How should I do this?  
One possibility would be to use

class Event \< Activerecord  
class OneTimeEvent \< Event  
class RecurringEvent \< Event

Does this work correctly?  
And how/where should I store the special information each type has  
(i.e. day\_of\_month for recurring)?

Thanks  
Jonas

---

<div class="post-metadata">

**Author:** ![jonas\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jonas\_s](https://www.ruby-forum.com/u/jonas_s)\
**Post date:** [September 18, 2008, 10:14pm UTC](https://www.ruby-forum.com/t/inheriting-model-detail/148981/2 "2008-09-18T22:14:42Z")

</div>

You’re probably looking for an STI (single table inheritance)  
implementation.

[http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance](http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance)

is a starting place.

---

<div class="post-metadata">

**Author:** ![jonas\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jonas\_s](https://www.ruby-forum.com/u/jonas_s)\
**Post date:** [September 20, 2008, 1:52pm UTC](https://www.ruby-forum.com/t/inheriting-model-detail/148981/3 "2008-09-20T13:52:39Z")

</div>

Thanks for the link.

At the bottom there, there is an unanswered question:

Q. What about model attributes when using STI?

eg. I have Page, Article and Comment all inheriting from ContentItem.  
Only comment uses the commentable\_id column.

Some of these models will have more attributes than others. How do I  
make sure the more specific atrributes are hidden or disabled from the  
parent model, while enabling those attributes for select models using  
those attributes?

That`s also interesting me.  
Can you tell me more about this?

Thanks  
Jonas

---

<div class="post-metadata">

**Author:** ![jonas\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jonas\_s](https://www.ruby-forum.com/u/jonas_s)\
**Post date:** [September 21, 2008, 1:10am UTC](https://www.ruby-forum.com/t/inheriting-model-detail/148981/4 "2008-09-21T01:10:09Z")

</div>

Hey guys,

I got another question: if I want a row to be part of both subclasses,  
is this possible?

And if not, how can I disable the attributes of one class (so I can  
have 2 different interfaces)?

Thanks,  
Jonas

---

<div class="post-metadata">

**Author:** ![jonas\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jonas\_s](https://www.ruby-forum.com/u/jonas_s)\
**Post date:** [September 21, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/inheriting-model-detail/148981/5 "2008-09-21T20:20:07Z")

</div>

On 20 Sep 2008, at 12:51, Jonas S. wrote:

> Some of these models will have more attributes than others. How do I  
> make sure the more specific atrributes are hidden or disabled from the  
> parent model, while enabling those attributes for select models using  
> those attributes?

Nothing builtin for doing this. If you have a lot of attributes like  
this then it can be a sign that STI isn’t the right tool for the job.

Fred
