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
I'm working out a solution using Doctrine Record Listeners by coding the preDqlSelect event. I think this is the best & easiest way to do things in a generic way, rather than having to modify every Table class and writing Tenant aware queries. With listeners, multi-tenancy will be completely transparent to developers.
Thanks for participating.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With