Skip to content

Commit 24ff21c

Browse files
committed
Fix find method used with arrays
1 parent 7b3a4f8 commit 24ff21c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/CachedBuilder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ public function find($id, $columns = ["*"])
6060
return parent::find($id, $columns);
6161
}
6262

63-
$idKey = collect($id)->implode('-');
64-
$preStr = is_array($id) ? 'find-list' : 'find';
65-
$cacheKey = $this->makeCacheKey($columns, null, "-" . $preStr . "_{$idKey}");
63+
$idKey = collect($id)
64+
->implode('_');
65+
$preStr = is_array($id)
66+
? 'find_list'
67+
: 'find';
68+
$cacheKey = $this->makeCacheKey($columns, null, "-{$preStr}_{$idKey}");
6669

6770
return $this->cachedValue(func_get_args(), $cacheKey);
6871
}

tests/Integration/CachedBuilder/FindTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ public function testFindModelResultsCreatesCache()
3333
$this->assertEmpty($liveResults->diffKeys($cachedResults));
3434
}
3535

36+
public function testFindMultipleModelResultsCreatesCache()
37+
{
38+
$authors = (new Author)->find([1, 2, 3]);
39+
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-find_list_1_2_3');
40+
$tags = [
41+
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
42+
];
43+
44+
$cachedResults = $this
45+
->cache()
46+
->tags($tags)
47+
->get($key)["value"];
48+
$liveResults = (new UncachedAuthor)->find([1, 2, 3]);
49+
50+
$this->assertEquals($authors->pluck("id"), $cachedResults->pluck("id"));
51+
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id"));
52+
}
53+
3654
public function testSubsequentFindsReturnDifferentModels()
3755
{
3856
$author1 = (new Author)->find(1);

0 commit comments

Comments
 (0)