Skip to content

Commit

Permalink
[9.x] Add withoutEagerLoads() method to Builder (#41950)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo authored Apr 13, 2022
1 parent 8a10e3f commit 560d2a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,16 @@ public function setEagerLoads(array $eagerLoad)
return $this;
}

/**
* Flush the relationships being eagerly loaded.
*
* @return $this
*/
public function withoutEagerLoads()
{
return $this->setEagerLoads([]);
}

/**
* Get the default key name of the table.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,19 @@ public function testEagerLoadRelationsLoadTopLevelRelationships()
$this->assertEquals(['foo'], $results);
}

public function testEagerLoadRelationsCanBeFlushed()
{
$builder = m::mock(Builder::class.'[eagerLoadRelation]', [$this->getMockQueryBuilder()]);

$builder->setEagerLoads(['foo']);

$this->assertSame(['foo'], $builder->getEagerLoads());

$builder->withoutEagerLoads();

$this->assertEmpty($builder->getEagerLoads());
}

public function testRelationshipEagerLoadProcess()
{
$builder = m::mock(Builder::class.'[getRelation]', [$this->getMockQueryBuilder()]);
Expand Down

0 comments on commit 560d2a7

Please sign in to comment.