Skip to content

Commit

Permalink
fix eager loading retroactively laravel/framework#51825
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius committed Dec 3, 2024
1 parent 2c6b073 commit ef3d94d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Eloquent/CustomRelations/RelationCleverTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait RelationCleverTrait
{
protected static ?string $noConstraintsForRelationName = null;
public static ?string $noConstraintsForRelationName = null;

/**
* Indicates if the relation is adding constraints.
Expand All @@ -19,10 +19,10 @@ trait RelationCleverTrait
public static function noConstraints(\Closure $callback, ?string $relationName = null): mixed
{
$previous = static::$constraints;
$previousNoConstraintsForRelationName = static::$noConstraintsForRelationName;
$previousNoConstraintsForRelationName = RelationCleverTrait::$noConstraintsForRelationName;

if ('' !== (string)$relationName) {
static::$noConstraintsForRelationName = $relationName;
RelationCleverTrait::$noConstraintsForRelationName = $relationName;
} else {
static::$constraints = false;
}
Expand All @@ -31,14 +31,14 @@ public static function noConstraints(\Closure $callback, ?string $relationName =
return $callback();
} finally {
static::$constraints = $previous;
static::$noConstraintsForRelationName = $previousNoConstraintsForRelationName;
RelationCleverTrait::$noConstraintsForRelationName = $previousNoConstraintsForRelationName;
}
}

protected function setConstraintsStaticFlag(BaseModel $model): void
{
if (
'' === (string)static::$noConstraintsForRelationName
'' === (string)RelationCleverTrait::$noConstraintsForRelationName
|| '' === (string)$model->nowEagerLoadingRelationNameWithNoConstraints
) {
return;
Expand Down Expand Up @@ -66,6 +66,6 @@ protected function setConstraintsStaticFlag(BaseModel $model): void
with nowEagerLoadingRelationNameWithNoConstraints = null
and with $noConstraintsForRelationName = 'rel' */
static::$constraints =
static::$noConstraintsForRelationName !== $model->nowEagerLoadingRelationNameWithNoConstraints;
RelationCleverTrait::$noConstraintsForRelationName !== $model->nowEagerLoadingRelationNameWithNoConstraints;
}
}

0 comments on commit ef3d94d

Please sign in to comment.