Skip to content

Instantly share code, notes, and snippets.

@rojotek
Created May 15, 2014 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rojotek/fc92f95ef40db2d249f7 to your computer and use it in GitHub Desktop.
Save rojotek/fc92f95ef40db2d249f7 to your computer and use it in GitHub Desktop.
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
Copy link

"class Departmet" should be "class Department"

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