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)
12361236 return  $ this  ;
12371237 }
12381238
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+ 
12391252 /** 
12401253 * Create a new instance of the model being queried. 
12411254 * 
Original file line number Diff line number Diff line change @@ -327,6 +327,15 @@ public function testWithoutMethodRemovesEagerLoadedRelationshipCorrectly()
327327 $ this  ->assertEmpty ($ instance ->getEagerLoads ());
328328 }
329329
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+ 
330339 public  function  testEagerLoadingWithColumns ()
331340 {
332341 $ model  = new  EloquentModelWithoutRelationStub ;
                                 You can’t perform that action at this time. 
               
                  
0 commit comments