Forum: Ruby on Rails has_many self references

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Brian L. (Guest)
on 2007-04-19 19:59
I am trying to model families in a database for tax and other purposes,
and am probably trying to hard. I setup a people table and a base class
person with
name, address, date of birth,etc.  Then I create classes of
husbands,wives, children that are all of the person class, and all are
mapped onto the single people table.  obviously these are
tables, but I having trouble with the has_many, belongs_to
relationships. I think I am confusing rails to some degree. It would
seem that these would be easy to model, but being a part-time
programmer, I am having troubles. when I use the
has_many (for children) and has_one (for husband,wife) I cannot get
rails to
consistently persist those relationships. I'm also using different names
for the relationship than the class (i.e. belongs_to :father,
:class_name => "Husband", foreign_key => "father"). I realize that I
don't have a full handle on how to do this more simply. (or how not to
confuse rails). can anybody point me  in the right direction?
This topic is locked and can not be replied to.