This is my first shot at using Rails… How does one establish symmetric
relationships? I’m building a web application where family
relationships between members is useful to know. I’m not sure how to
get the joins to work though…
I have a table of Members and I want to capture, for example, spousal
relationships. The problem I’m running into is that both sides of the
relationship will point back to the ‘members’ table, but must have
different column names.
class CreateRelationships < ActiveRecord::Migration
def self.up
create_table :relationships do |t|
t.column :member_id, :integer
t.column :member2_id, :integer
#preset tags such as “spousal”, “parental”, “other”
t.column :type, :string, :limit => 15
#type to be used for “other”
t.column :type_for_other, :string, :limit => 50
end
end
def self.down
drop_table :relationships
end
end
Using a ‘has_many :relations, :through => :relationships’ link seems
appropriate, but I’m not sure how to key it to both columns.
class Member < ActiveRecord::Base
has_many :relations, :through => :relationships
end
Is this a job for the :source attribute?