Create a gist now

Instantly share code, notes, and snippets.

Final has_one code
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
@rsmithlal

"class Departmet" should be "class Department"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment