Skip to content

Commit 2032ab0

Browse files
author
Admin
committed
Fix eager loading for MorphMany::one and HasMany::one methods
1 parent e8ba477 commit 2032ab0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Eloquent/CustomRelations/HasCleverRelationships.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ public function one()
197197

198198
return Relation::macroNoConstraints(function () use ($relationName): HasOne {
199199
$this->parent->nowEagerLoadingRelationNameWithNoConstraints = $relationName;
200+
$builder = $this->getQuery()->clone();
201+
$builder->setQuery($builder->getQuery()->clone());
200202

201203
$hasOne = new HasOne(
202-
$this->getQuery(),
204+
$builder,
203205
$this->parent,
204206
$this->foreignKey,
205207
$this->localKey
@@ -321,9 +323,11 @@ public function one()
321323

322324
return Relation::macroNoConstraints(function () use ($relationName): MorphOne {
323325
$this->getParent()->nowEagerLoadingRelationNameWithNoConstraints = $relationName;
326+
$builder = $this->getQuery()->clone();
327+
$builder->setQuery($builder->getQuery()->clone());
324328

325329
$morphOne = new MorphOne(
326-
$this->getQuery(),
330+
$builder,
327331
$this->getParent(),
328332
$this->morphType,
329333
$this->foreignKey,

0 commit comments

Comments
 (0)