I’m trying to make a rails model that contains two different “has_one” attributes of the same class. I feel like there is an easier way to do this, but I can’t think of it right now.
So, lets say I’d like to create a wedding model in rails
class Wedding < ActiveRecord::Base
has_one :groom, :class_name => 'Person'
has_one :bride, :class_name => 'Person'
end
class Person < ActiveRecord::Base
attr_accessible :wedding_id
belongs_to :wedding
end
My goal is to have access to the groom object from the wedding object. (be able to call @wedding.groom.name or whatever) Currently there is no way for the Wedding Model to know which “person” is the Bride and which is the Groom.
Should I be using single table inheretance? Or should I be using foreign keys?
Is there a better way to think of the whole problem?
Your associations are backwards for the functionality that you want..