Skip to content

Instantly share code, notes, and snippets.

@certainty
Created July 19, 2012 11:17
Show Gist options
  • Save certainty/3143130 to your computer and use it in GitHub Desktop.
Save certainty/3143130 to your computer and use it in GitHub Desktop.
Self ref
class Company < ActiveRecord::Base
attr_accessible :name
has_many :parent_associations, :class_name => 'Association', :foreign_key => 'child_id'
has_many :child_associations, :class_name => 'Association', :foreign_key => 'parent_id'
has_many :parents, :through => :parent_associations, :source => :parent
has_many :children, :through => :child_associations, :source => :child
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment