Skip to content

Commit 2923ea5

Browse files
committed
Add test to check that non-eagerloaded relationships will also be cached
1 parent 98f53e1 commit 2923ea5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/Unit/CachedBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,19 @@ public function testNestedRelationshipEagerloading()
438438
$this->assertEmpty($authors->diffAssoc($cachedResults));
439439
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
440440
}
441+
442+
public function testNonEagerloadedRelationshipResolvesThroughCachedBuilder()
443+
{
444+
$books = (new Author)->first()->books;
445+
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_';
446+
$tags = [
447+
'genealabslaravelmodelcachingtestsfixturesbook',
448+
];
449+
450+
$cachedResults = cache()->tags($tags)->get($key);
451+
$liveResults = (new UncachedAuthor)->first()->books;
452+
453+
$this->assertEmpty($books->diffAssoc($cachedResults));
454+
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
455+
}
441456
}

0 commit comments

Comments
 (0)