On Sat, Sep 26, 2009 at 2:01 PM, nb <saltyban...@gmail.com> wrote:
>
> So I have this question:
>
> Suppose I have these 3 models:
>
> class Company < ActiveRecord::Base
>  has_many :departments
>  has_many :employees
> end
>
> class Department < ActiveRecord::Base
>  has_many :employees
>  belongs_to :company
> end
>
> class Employee < ActiveRecord::Base
>  belongs_to :company
>  belongs_to :department
> end
>
> Furthermore, suppose the domain I am modeling requires that I support
> the existence of employees that do not belong to any department
> (otherwise I would declare that Company has_many :employees, :through
> => :departments instead).


Well one way to finesse this might be to have a fictional/notional
catch-all department for each company, like "company staff" which acts
as a placeholder for employes not actually belonging to a 'real'
department.

-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to