I'm setting up a SaaS style website wherein I will have multiple clients all managing their workflows and data on the same site -- and thus the same database.
I'm not even sure if there is a word for this concept, but is there any established way of auto-segregating the data so that any ActiveRecord calls to the database are filtered/restricted by the correct client_id of the user that is logged in?
The straightforward way would be of course to just add a "where client_id = ?
" and put in the user's client id... onto the end of every single ActiveRecord request.
Is there any before filter idea for the Models, so that any find method (including the dynamic ones) would tack on the client_id
to them automatically?. So I could just do Model.find_by_what_I_want(foo)
, and it would automatically know to limit that to only records owned by the correct client id even though I didn't specify it explicitly?