Skip to content

Commit

Permalink
Revert "Resolve #854"
Browse files Browse the repository at this point in the history
This reverts commit a1c3442.
  • Loading branch information
stancl committed May 15, 2022
1 parent a1c3442 commit 4d95e88
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Database/Concerns/BelongsToTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ trait BelongsToTenant

public function tenant()
{
return $this->belongsTo(config('tenancy.tenant_model'), static::$tenantIdColumn);
return $this->belongsTo(config('tenancy.tenant_model'), BelongsToTenant::$tenantIdColumn);
}

public static function bootBelongsToTenant()
{
static::addGlobalScope(new TenantScope);

static::creating(function ($model) {
if (! $model->getAttribute(static::$tenantIdColumn) && ! $model->relationLoaded('tenant')) {
if (! $model->getAttribute(BelongsToTenant::$tenantIdColumn) && ! $model->relationLoaded('tenant')) {
if (tenancy()->initialized) {
$model->setAttribute(static::$tenantIdColumn, tenant()->getTenantKey());
$model->setAttribute(BelongsToTenant::$tenantIdColumn, tenant()->getTenantKey());
$model->setRelation('tenant', tenant());
}
}
Expand Down

3 comments on commit 4d95e88

@stancl
Copy link
Member Author

@stancl stancl commented on 4d95e88 May 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach didn't work since the trait is used by many models, so in v4 we'll probably move to some config key

@nikkuang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the hidden issues why this was reverted?

@stancl
Copy link
Member Author

@stancl stancl commented on 4d95e88 Jul 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to specify the value on the trait so that it's used by ALL of the models that implement it. In PHP 8.1 we can't do that without warnings.

Please sign in to comment.