On 11 Apr 2008, at 17:01, shenry wrote:
>
> I am working on a site which tracks "ferms" (read: widgets)...
each
> ferm belongs to one company, one company can have many ferms.
>
> One company can also have many users with different access priveliges,
> and company administrators would invite other users to access the
> company''s site.
>
> Also, one user can belong to different companies and perhaps have
> different access at each company.
>
> I''m struggling to determine how to nest the models, here is my
best
> guess:
>
> User
> has_many :companies, :through => :companies_users
> end
>
> Company
> has_many :ferms
> has_many :users, :through => :companies_users
> end
>
You sought of want nested has_many :throughs, at which point it would
become obvious.
Rails doesn''t have that baked in, but there is a plugin (just google
for nested has_many through)
Fred> The companies_users join table would have a column that describes the
> access (1,2,3?) for that user at that company.
>
> When a user logs in and wants to view his list of ferms at Company X
> the Ferms#index controller would include
>
> @ferms = Ferm.find(:all, :conditions => ["company = ?",
User.company])
>
> Am I on the right track with this? Any help is appreciated.
>
> SH
>
> >
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---