我在 Ruby on Rails 3 中工作。并试图绘制出三个模型来模拟公司、员工及其各自部门的数据。
得出以下解决方案:
class Company < ActiveRecord::Base
has_many :departments
has_many :employees, through => :departments
end
class Department < ActiveRecord::Base
belongs_to :company
has_many :employees
has_one :department_description
end
class DepartmentDescription < ActiveRecord::Base
belongs_to :department
end
class Employee < ActiveRecord::Base
belongs_to :department
end
这是关联这些模型的“正确”方式吗?