views:

37

answers:

1

I know it's possible to create Any relationships where the related record could be of any type.

Is there a way to tell the ActiveRecord the records in a table belong to many different types even when there is no relationships? For example I have a table in which there is a string field that stores the type of each record in table. I'd like ActiveRecord to recognize the type of each record and subsequently instantiate the correct type when querying that table.

Can anyone say if that's possible?

+1  A: 

There are three ways of doing this. Each method is design to suit each of these three situations:

Single Table Inheritance uses a single table with a discriminator column to determine which type each row contains.

Class Table Inheritance involves using different tables for each class where the "base" table defined the primary key, and the others "inherit" it.

Concrete Table Inheritance is a third way to map a class hierarchy, each concrete class has its own database table.

http://www.castleproject.org/activerecord/documentation/v1rc1/usersguide/typehierarchy.html

Am
copied from the docs: http://www.castleproject.org/activerecord/documentation/trunk/usersguide/typehierarchy.html
Mauricio Scheffer