We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fcd90b9 commit a3d63c8Copy full SHA for a3d63c8
1 file changed
tests/Database/DatabaseEloquentHasOneOfManyTest.php
@@ -437,6 +437,21 @@ public function testEagerLoadingWithMultipleAggregates()
437
$this->assertSame($user2Price->id, $users[1]->price->id);
438
}
439
440
+ public function testEagerLoadingWithConstraintsAppliesToSubQuery()
441
+ {
442
+ $user = HasOneOfManyTestUser::create();
443
+ $user->logins()->create(); // ID 1
444
+ $login2 = $user->logins()->create(); // ID 2
445
+ $user->logins()->create(); // ID 3
446
+
447
+ $users = HasOneOfManyTestUser::with(['latest_login' => function ($q) {
448
+ $q->where('logins.id', '<', 3);
449
+ }])->get();
450
451
+ $this->assertNotNull($users[0]->latest_login);
452
+ $this->assertSame($login2->id, $users[0]->latest_login->id);
453
+ }
454
455
public function testWithExists()
456
{
457
$user = HasOneOfManyTestUser::create();
0 commit comments