Inheriting model detail

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

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

http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance

is a starting place.

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

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

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?

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