Skip to content

Instantly share code, notes, and snippets.

@ricardodovalle
Created August 1, 2013 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardodovalle/6127359 to your computer and use it in GitHub Desktop.
Save ricardodovalle/6127359 to your computer and use it in GitHub Desktop.
create_table :manage_relation do |t|
t.references :employee_id
t.references :manager_id
end
create_table :subordinate_relation do |t|
t.references :employee_id
t.references :subordinate_id
end
class Employee < ActiveRecord::Base
has_many :subordinates,
:through => :subordinate_relation,
:class_name => "Employee",
:foreign_key => "subordinate_id"
has_many :managers,
:through => :manage_relation,
:class_name => "Employee",
:foreign_key => "manager_id"
belongs_to :employee,
:class_name => "Employee"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment