Subclassing a model

Is it possible to define a subclass for a model, that defines additional
data columns, which are stored in a separate table?

Is there any description, how to do this?

On Thu, Aug 19, 2010 at 8:05 AM, Fritz T. [email protected]
wrote:

Is it possible to define a subclass for a model, that defines additional
data columns, which are stored in a separate table?

What you are describing is “Multiple Table Inheritance”. I don’t
think stock rails handles this. Rails supports “Single Table
Inheritance”[1] in which you’ll store the union of all column types in
the base table.

[1] ActiveRecord::Base

Is there any description, how to do this?

For STI make a table for the base class and subclass arbitrarily.


med vänlig hälsning
David JH

David J. Hamilton wrote:

On Thu, Aug 19, 2010 at 8:05 AM, Fritz T. [email protected]
wrote:

Is it possible to define a subclass for a model, that defines additional
data columns, which are stored in a separate table?

What you are describing is “Multiple Table Inheritance”. I don’t
think stock rails handles this. Rails supports “Single Table
Inheritance”[1] in which you’ll store the union of all column types in
the base table.

But you could use has_one.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On 19 August 2010 16:05, Fritz T. [email protected] wrote:

Is it possible to define a subclass for a model, that defines additional
data columns, which are stored in a separate table?

Is there any description, how to do this?

You can certainly subclass a model.

Then the subclass could have a :has_one relationship to another model
with the extra columns which the superclass doesn’t have.

If you want to make it transparent, you can delegate the calls for the
extra tables in the associated model, so instead of:
foo.bar.extra_value
you can call:
foo.extra_value

Oh thanks. It seems, I not see wood for trees…