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
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
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
Is this a job for the :source attribute?