Skip to content

Commit 327a514

Browse files
committed
Add tests;
1 parent 8f157cc commit 327a514

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/RelationsTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,13 @@ public function testMorph(): void
634634
$photo = Photo::first();
635635
$this->assertEquals($photo->hasImage->name, $user->name);
636636

637+
// eager load
637638
$user = User::with('photos')->find($user->id);
638639
$relations = $user->getRelations();
639640
$this->assertArrayHasKey('photos', $relations);
640641
$this->assertEquals(1, $relations['photos']->count());
641642

643+
// inverse eager load
642644
$photos = Photo::with('hasImage')->get();
643645
$relations = $photos[0]->getRelations();
644646
$this->assertArrayHasKey('hasImage', $relations);
@@ -648,7 +650,7 @@ public function testMorph(): void
648650
$this->assertArrayHasKey('hasImage', $relations);
649651
$this->assertInstanceOf(Client::class, $photos[1]->hasImage);
650652

651-
// inverse
653+
// inverse relationship
652654
$photo = Photo::query()->create(['url' => 'https://graph.facebook.com/hans.thomas/picture']);
653655
$client = Client::create(['name' => 'Hans Thomas']);
654656
$photo->hasImage()->associate($client)->save();
@@ -666,6 +668,14 @@ public function testMorph(): void
666668
$this->assertInstanceOf(Client::class, $photo->hasImageWithCustomOwnerKey);
667669
$this->assertEquals($client->cclient_id, $photo->has_image_with_custom_owner_key_id);
668670
$this->assertEquals($client->id, $photo->hasImageWithCustomOwnerKey->id);
671+
672+
// inverse eager load with custom ownerKey
673+
$photos = Photo::with('hasImageWithCustomOwnerKey')->get();
674+
$check = $photos->last();
675+
$relations = $check->getRelations();
676+
$this->assertArrayHasKey('hasImageWithCustomOwnerKey', $relations);
677+
$this->assertInstanceOf(Client::class, $check->hasImageWithCustomOwnerKey);
678+
669679
}
670680

671681
public function testMorphToMany(): void

0 commit comments

Comments
 (0)