File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
src/Illuminate/Database/Eloquent Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1236,6 +1236,19 @@ public function without($relations)
1236
1236
return $ this ;
1237
1237
}
1238
1238
1239
+ /**
1240
+ * Set the relationships that should be eager loaded while removing any previously added eager loading specifications.
1241
+ *
1242
+ * @param mixed $relations
1243
+ * @return $this
1244
+ */
1245
+ public function withOnly ($ relations )
1246
+ {
1247
+ $ this ->eagerLoad = [];
1248
+
1249
+ return $ this ->with ($ relations );
1250
+ }
1251
+
1239
1252
/**
1240
1253
* Create a new instance of the model being queried.
1241
1254
*
Original file line number Diff line number Diff line change @@ -327,6 +327,15 @@ public function testWithoutMethodRemovesEagerLoadedRelationshipCorrectly()
327
327
$ this ->assertEmpty ($ instance ->getEagerLoads ());
328
328
}
329
329
330
+ public function testWithOnlyMethodLoadsRelationshipCorrectly ()
331
+ {
332
+ $ model = new EloquentModelWithoutRelationStub ();
333
+ $ this ->addMockConnection ($ model );
334
+ $ instance = $ model ->newInstance ()->newQuery ()->withOnly ('taylor ' );
335
+ $ this ->assertNotNull ($ instance ->getEagerLoads ()['taylor ' ]);
336
+ $ this ->assertArrayNotHasKey ('foo ' , $ instance ->getEagerLoads ());
337
+ }
338
+
330
339
public function testEagerLoadingWithColumns ()
331
340
{
332
341
$ model = new EloquentModelWithoutRelationStub ;
You can’t perform that action at this time.
0 commit comments