hipsterjazzbo / Landlord

A simple, single database multi-tenancy solution for Laravel 5.2+
MIT License
615 stars 138 forks source link

WIth multiple tenants Landlord uses first tenant id for the other tenant scopes #82

Open rikvdlooi opened 6 years ago

rikvdlooi commented 6 years ago

When you scope on multiple tenants Landlord, landlord will use the id of the first tenant on all other tenants.

How to reproduce (some 'pseudo' code):

Model with two different tenants

class MyModel extends Model {
    use BelongsToTenants;

    public $tenantColumns = ['tenant_a_id', 'tenant_b_id'];
}

Add Tenants

Landlord::AddTenant('tenant_a_id', 1);
Landlord::AddTenant('tenant_b_id', 2);

Get results

MyModel::all();

If you use barryvdh/laravel-debugbar you can see that the query will be like this:

select * from my_model where tenant_a_id = 1 and tenant_b_id = 1;

The $id for Tenant A is also used for the scope of Tenant B.

aluferraz commented 6 years ago

I think this is the same case as #85

rikvdlooi commented 6 years ago

Yes @aluferraz. It looks like it is the same issue. At least (almost) the same solution.

aluferraz commented 6 years ago

@HipsterJazzbo any thoughts on this ? :)