Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenants getting mixed up #85

Open
aluferraz opened this issue Nov 21, 2017 · 1 comment
Open

Tenants getting mixed up #85

aluferraz opened this issue Nov 21, 2017 · 1 comment

Comments

@aluferraz
Copy link

Hi,

After upgrading from Lumen 5.4 to 5.5 and Landlord from 2.0.6 to 2.0.8, my tenants are getting mixed up.

This is the piece of code where a wrong value is added to the "where":

TenantManager:143

  $this->modelTenants($model)->each(function ($id, $tenant) use ($model) {
            $model->addGlobalScope($tenant, function (Builder $builder) use ($tenant, $id, $model) {
                if($this->getTenants()->first() && $this->getTenants()->first() != $id){
                    $id = $this->getTenants()->first();
                }

                $builder->where($model->getQualifiedTenant($tenant), '=', $id);
            });
        });

As you can see in the attached picture, the tenant value for the tenant id is 1. However, the library is setting the value of the tenant to "DS", which is the value of another tenant belongsToSolution.

2017-11-21_15-50-53

The problem seems to be that the library is always getting the first tenant as the value, instead of getting the tenant with the corresponding key. I think the correct code would be:

$this->modelTenants($model)->each(function ($id, $tenant) use ($model) {
            $model->addGlobalScope($tenant, function (Builder $builder) use ($tenant, $id, $model) {		
		$id = $this->getTenantId($tenant);

                $builder->where($model->getQualifiedTenant($tenant), '=', $id);
            });
        });

Lumen: 5.5
LandLord: 2.0.8
PHP: 7.1.9
Enviroment: WAMP Stack (Windows 10) and LAMP Stack (Ubuntu 16)

@aluferraz
Copy link
Author

@hipsterjazzbo please, don't give up on us :'(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant