Created
May 15, 2014 21:58
-
-
Save rojotek/fc92f95ef40db2d249f7 to your computer and use it in GitHub Desktop.
Final has_one code
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 | |
belongs_to: :department | |
has_one :organization, through: :department | |
end | |
class Departmet | |
belongs_to :organization | |
has_many :project_departments | |
has_many :projects, through: :project_departments | |
has_many :employees | |
has_one :head_of_department, -> { where role: 'department_head' }, class_name: 'Employee' | |
end | |
class Organization | |
has_many :departments | |
has_many :employees through: :departments | |
end | |
class Project | |
has_many :project_departments | |
has_many :departments, through: :project_departments | |
has_one :project_department, ->(department) { where department: department }, class_name: 'ProjectDepartment' | |
end | |
class ProjectDepartment | |
belongs_to :project | |
belongs_to :project | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"class Departmet" should be "class Department"