Ruby on Rails inheritance

224 Views Asked by At

I want to I achieve the following model structure in my Rails application having 3 separate tables - Value, DecimalValue and TextValue - in which DecimalValue and TextValue inherit from Value. The idea is that Value should contain only the id, and the child tables should refer to that id. How can I implement this based o ROR?

Value model (id, type) DecimalValue (value_id, value:decimal) TextValue (value_id, value:string)

Thanks in advance!

1

There are 1 best solutions below

0
On

You should try Polymorphic Associations.

Here is good RailsCast about it