Rails - inheritance hierarchy of classes where an subtipe can play two roles
Posted
by Miquel
on Stack Overflow
See other posts from Stack Overflow
or by Miquel
Published on 2010-05-23T14:47:34Z
Indexed on
2010/05/23
14:50 UTC
Read the original article
Hit count: 200
ruby-on-rails
|ruby
I need to model Owners and Rentees in an application, so you have stuff that is always owned by someone and can be rented for someone else. I first approached this problem with Single Table Inheritance because both types of person will share all attributes, so you would have a model called Person associated to a table people with Owner and Rentee inheriting from Person.
The problem is that Single type inheritance discerns subtypes using a field type and therefore a record in the table can represent either an Owner or a Rentee but not both at the same time, while in the real context you can have an Owner which is renting something from another Owner and therefore that person is at the same time an Owner and a Rentee.
How would you approach this problem? Would you use separated tables fro owners and rentees? Is there any other type of table inheritance in Rails?
© Stack Overflow or respective owner