Skip to content

Commit a3d63c8

Browse files
committed
Add integration test for eager load oneOfMany constraints
1 parent fcd90b9 commit a3d63c8

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/Database/DatabaseEloquentHasOneOfManyTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,21 @@ public function testEagerLoadingWithMultipleAggregates()
437437
$this->assertSame($user2Price->id, $users[1]->price->id);
438438
}
439439

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+
440455
public function testWithExists()
441456
{
442457
$user = HasOneOfManyTestUser::create();

0 commit comments

Comments
 (0)