Sunday, June 20, 2010

[Rails] Multiple has_one to same table

Your input/experience appreciated. I have noticed multiple
discussions regarding husband and wife. But none really end in a
"this is a the best way to handle things." Here is my situation. I'm
recording information on couples -- husband and wife, one of each. If
the two are no longer married, the couple will evaporate. If either
person is deleted, then couple will evaporate. I originally thought
of having all individuals in one table, persons, and then creating
couple with alink to each person.

# == Schema Information
# Schema version: 20100620123354
#
# Table name: couples
#
# id :integer not null, primary key
# active :boolean
# husband_id :integer # reference to persons table
# wife_id :integer # reference to persons table

I was then thinking:

belongs_to :husband,:class_name=>"Person",:foreign_key=>"husband_id"
belongs_to :wife,:class_name=>"Person",:foreign_key=>"wife_id"

and then having classes "Husband < Person" and "Wife < Person". Is
this feasible?

I am so torn I don't know what step to take next. I'm early in
development so I can do anything. But what I want to do is what is
best.

Do I stick with a couples table and one persons table?

Do I create separate tables for husbands and wives? If I do this, can
I create one Person class and Husband & Wife models inheriting
Person...that way the two tables are created and migrated
separately?

You input is really appreciated.
dvn

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate