Skip to content

Commit a49ca01

Browse files
committed
Disable queries on relations if model is disabled
1 parent c858587 commit a49ca01

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/CachedBuilder.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,18 @@ public function paginate(
166166
return $this->cachedValue(func_get_args(), $cacheKey);
167167
}
168168

169-
/**
170-
* Get the relation instance for the given relation name.
171-
* This is overloaded so we can disable model cache on
172-
* relations if parent has disabled model caching.
173-
*
174-
* @param string $name
175-
* @return \Illuminate\Database\Eloquent\Relations\Relation
176-
*/
177-
public function getRelation($name)
178-
{
179-
$relation = parent::getRelation($name);
180-
181-
if(!$this->isCachable() && is_a($relation->getQuery(), self::class)){
182-
$relation->getQuery()->disableModelCaching();
183-
}
184-
185-
return $relation;
186-
}
169+
public function getRelation($name)
170+
{
171+
$relation = parent::getRelation($name);
172+
173+
if (! $this->isCachable()
174+
&& is_a($relation->getQuery(), self::class)
175+
) {
176+
$relation->getQuery()->disableModelCaching();
177+
}
178+
179+
return $relation;
180+
}
187181

188182
protected function recursiveImplodeWithKey(array $items, string $glue = "_") : string
189183
{

0 commit comments

Comments
 (0)