diff --git a/src/CacheKey.php b/src/CacheKey.php index 025b431..cef259f 100644 --- a/src/CacheKey.php +++ b/src/CacheKey.php @@ -164,6 +164,10 @@ protected function getValuesFromWhere(array $where) : string return implode("_", collect($where["values"])->flatten()->toArray()); } + if (is_array((new Arr)->get($where, "value"))) { + return implode("_", collect($where["value"])->flatten()->toArray()); + } + return (new Arr)->get($where, "value", ""); } diff --git a/tests/Integration/CachedBuilder/WhereJsonContainsTest.php b/tests/Integration/CachedBuilder/WhereJsonContainsTest.php index aab68ec..71ebcf8 100644 --- a/tests/Integration/CachedBuilder/WhereJsonContainsTest.php +++ b/tests/Integration/CachedBuilder/WhereJsonContainsTest.php @@ -49,4 +49,27 @@ public function testWithInUsingCollectionQuery() $this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); } + + public function testWithInUsingCollectionQueryWithArrayValues() + { + $key = sha1("genealabs:laravel-model-caching:pgsql:testing:authors:genealabslaravelmodelcachingtestsfixturesauthor-finances->tags_jsoncontains_[\"foo\",\"bar\"]-authors.deleted_at_null"); + $tags = [ + 'genealabs:laravel-model-caching:pgsql:testing:genealabslaravelmodelcachingtestsfixturesauthor', + ]; + + $authors = (new Author) + ->whereJsonContains("finances->tags", ['foo', 'bar']) + ->get(); + $liveResults = (new UncachedAuthor) + ->whereJsonContains("finances->tags", ['foo', 'bar']) + ->get(); + + $cachedResults = $this + ->cache() + ->tags($tags) + ->get($key)['value']; + + $this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); + $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); + } } diff --git a/tests/database/factories/AuthorFactory.php b/tests/database/factories/AuthorFactory.php index cd26488..a88e002 100644 --- a/tests/database/factories/AuthorFactory.php +++ b/tests/database/factories/AuthorFactory.php @@ -11,6 +11,7 @@ "total" => 5000, "weekly" => 100, "daily" => 20, + 'tags' => ['foo', 'bar'], ], "is_famous" => $faker->boolean(), ];