Multi-user multi-company design

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

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

On 11 Apr 2008, at 17:01, shenry wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs