Uh ... ended up changing things to use the Has Many Through association 
... now it all works and looks like this:


#Created a parties table
class CreateParties < ActiveRecord::Migration
  def change
    create_table :parties do |t|
      t.string :type

      t.timestamps
    end
  end
end

#created a join table to associate one party to another
class CreateAssociatedParties < ActiveRecord::Migration

  def change
    create_table :associated_parties do |t|
      t.integer :association_type_id
      t.integer :parent_id
      t.integer :child_id
    end
  end

end

#With a Party class like this using hmt
class Party < ActiveRecord::Base

  has_many :primary_associations, :foreign_key => 'parent_id',
                                  :class_name => 'AssociatedParty',
                                  :dependent => :destroy
  has_many :children, :through => :primary_associations

  has_many :secondary_associations, :foreign_key => 'child_id',
                                    :class_name => 'AssociatedParty',
                                    :dependent => :destroy
  has_many :parents,  :through =>   :secondary_associations

end

#And the join class like this
class AssociatedParty < ActiveRecord::Base

  belongs_to :parent, :class_name => "Party"
  belongs_to :child, :class_name => "Party"

end

-- 
Posted via http://www.ruby-forum.com/.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to