[Rails] "partitioning" table access
Francois Beausoleil
francois.beausoleil at gmail.com
Wed Apr 5 18:01:03 GMT 2006
Hi !
2006/4/5, Tony Buser <tbuser at 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 !
--
François Beausoleil
http://blog.teksol.info/
More information about the Rails
mailing list