diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 365247f69f68..1b41b2162d55 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -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. * diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index b8a0c54f0b17..044167daf033 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -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()]);