Last active
April 1, 2016 08:08
-
-
Save wolfieorama/3dbf73ab3fe9274ce4779b6abd89b070 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
class Employee < ActiveRecord::Base | |
has_many :subordinates, class_name: "Employee", foreign_key: "manager_id" | |
belongs_to :manager, class_name: "Employee" | |
belongs_to :team | |
has_one :team, foreign_key: "manager_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
create_table "employees", force: :cascade do |t| | |
t.string "name" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.integer "manager_id" | |
t.integer "team_id" | |
end | |
create_table "teams", force: :cascade do |t| | |
t.string "team_name" | |
t.integer "sec_team_id" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.integer "ter_team_id" | |
t.integer "manager_id" | |
end | |
add_index "teams", ["sec_team_id"], name: "index_teams_on_sec_team_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 Team < ActiveRecord::Base | |
#self join within teams | |
has_one :teir1, class_name: "Team", foreign_key: "sec_team_id" | |
has_one :teir2, class_name: "Team", foreign_key: "ter_team_id" | |
belongs_to :sec_team, class_name: "Team" | |
belongs_to :ter_team, class_name: "Team" | |
#across users | |
has_many :subordinates, class_name: "Employee", foreign_key: "subordinate_id" | |
belongs_to :manager, class_name: "Employee" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment