Created
August 1, 2013 00:01
-
-
Save ricardodovalle/6127359 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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