Forum: Ruby on Rails "partitioning" table access

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1843b506d589247217d2d1e85add8336?d=identicon&s=25 Tony Buser (gr0k)
on 2006-04-05 19:56
(Received via mailing list)
Hopefully someone can give me some advice on how to approach this
problem... I'm getting ready to start a large new project where
several different organizations would be working with a lot of tables.
 Each table would have an organization_id field to signify which
organization owns that record.  Organizations would only be able to
view/edit records they own.  Potentially thousands of organizations
and dozens of tables.

I'm hoping rails has some magic way to handle this in the model
somehow.  The alternative is I'd have to include a where
organization_id = to virtually every single query...

btw, I'm using mysql, in case there might be some way to accomplish
this on the database level.
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 François Beausoleil (fbeausoleil)
on 2006-04-05 20:02
(Received via mailing list)
Hi !

2006/4/5, Tony Buser <tbuser@gmail.com>:
> I'm hoping rails has some magic way to handle this in the model
> somehow.  The alternative is I'd have to include a where
> organization_id = to virtually every single query...

You'll need the org_id column on your child tables anyway, but Rails
allows you to do it this way:

class Organization < AR::Base
  has_many :postings
  has_many :employees
  has_many :drafts
end

class Posting < AR::Base
  belongs_to :organization
end

organization.postings.find(:all, ...)

You can use a before_filter in ApplicationController to get the org
into a known variable.  This is not unlike regular authentication.

Hope that helps !
34f5b045aec62235c17458650ea75353?d=identicon&s=25 Steve Koppelman (hatless)
on 2006-04-05 20:16
Also look at with_scope and at the ScopedAccess plugin. Google it.

Tony Buser wrote:
> Hopefully someone can give me some advice on how to approach this
> problem... I'm getting ready to start a large new project where
> several different organizations would be working with a lot of tables.
>  Each table would have an organization_id field to signify which
> organization owns that record.  Organizations would only be able to
> view/edit records they own.  Potentially thousands of organizations
> and dozens of tables.
>
> I'm hoping rails has some magic way to handle this in the model
> somehow.  The alternative is I'd have to include a where
> organization_id = to virtually every single query...
>
> btw, I'm using mysql, in case there might be some way to accomplish
> this on the database level.
1843b506d589247217d2d1e85add8336?d=identicon&s=25 Tony Buser (gr0k)
on 2006-04-05 23:03
(Received via mailing list)
Well that makes total sense and I can't believe I didn't think of it
before.  :)

Thanks!
This topic is locked and can not be replied to.