if users --> students // employee (single table inheritence), , both belong organization --> school // work (single table inheritance), proper way write association? put organization_id user class, , wrote belongs /has many in respective subclasses, when call user.school, "nil", though has organization_id = 1.
user.rb
class user < activerecord::base attr_accessible :email, :name, :password, :organization_id, :type end
student.rb
class student < user belongs_to :school end
employee.rb
class employee < user belongs_to :company end
organization.rb
class organization < activerecord::base attr_accessible :name end
school.rb
class school < organization has_many :students end
company.rb
class company < organization has_many :employees end
i advise not use single-table inheritance. benefits it? students , employees different things, schools , companies. should separate tables. make life so, simpler in long-run. , if don't use single-table inheritance, problem goes away too.
Comments
Post a Comment