How would i build a multi tenant architecture using YII?
I have a database. all tables have a tenant_id which identifies/segregates data to a single tenant.
example: … projects table (id, name, tenant_id)
my approach, (pseudo code)
On login, set session(tenant) to user.tenant_id.
When display data, select data where tenant = session variable.
on insert/update, delete, get user.tenant (make sure it is the correct tenant), then do action.
is session variable a viable choice? session variable is unstable in my experience.
how can i set session variable condition (as in default scope) once and not in every single model?
any other way that would make this easier/more secure? What are you doing?