I am trying to implement a multi-tenant application, that is
- data of all clients in a single database
- each shared table has a tenant_id
field to separate data
I wish to achieve data separation by adding where('tenant_id = ', $user->getTenantID())
{pseudoc-code}
to all SELECT queries
I could not find any solution up-front, but here are possible approaches I am considering.
1) crude approach:
customizing all fetchAll
and fetchOne
functions in every class (I will go mad!)
2) using listeners:
possibly coding for the preDqlSelect
event and adding the 'where' to all queries
3) override buildQuery
(): could not find an example of this for front-end
4) implement contentformfilter
: again need a pointer
Would appreciate if someone could validate these & comment on efficieny, suitability. Also, if anyone has achieved multitenancy using another strategy, pl share. Thanks