diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..60777e7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +* text=auto + +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/phpunit.xml export-ignore +/tests export-ignore diff --git a/src/CachedBuilder.php b/src/CachedBuilder.php index fd073f8..07a8e77 100644 --- a/src/CachedBuilder.php +++ b/src/CachedBuilder.php @@ -73,19 +73,16 @@ protected function getQueryColumns(array $columns) : string protected function getWhereClauses() : string { - // dump($this->query->wheres); return collect($this->query->wheres)->reduce(function ($carry, $where) { - if (! $where['column'] ?? false) { - return $carry . ''; - } - - $value = $where['value'] ?? ''; + $value = array_get($where, 'value'); - if ($where['values'] ?? false) { - $value .= 'in_' . implode('_', $where['values']); + if (in_array($where['type'], ['In', 'Null', 'NotNull'])) { + $value = strtolower($where['type']); } - $value = $where['type'] === 'Null' ? 'null' : $value; + if (is_array(array_get($where, 'values'))) { + $value .= '_' . implode('_', $where['values']); + } return "{$carry}-{$where['column']}_{$value}"; }) ?: ''; diff --git a/tests/Fixtures/UncachedBook.php b/tests/Fixtures/UncachedBook.php index 0e92d45..18aa289 100644 --- a/tests/Fixtures/UncachedBook.php +++ b/tests/Fixtures/UncachedBook.php @@ -1,10 +1,10 @@ push( - (new Author)->with('books.publisher') - ->first() - ); + $authors = collect([(new Author)->with('books.publisher') + ->first()]); + $key = 'genealabslaravelmodelcachingtestsfixturesauthor-books-books.publisher-first'; $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', @@ -426,15 +425,10 @@ public function testNestedRelationshipEagerloading() 'genealabslaravelmodelcachingtestsfixturespublisher', ]; - $cachedResults = collect()->push( - cache()->tags($tags) - ->get($key) - ); - - $liveResults = collect()->push( - (new UncachedAuthor)->with('books.publisher') - ->first() - ); + $cachedResults = collect([cache()->tags($tags) + ->get($key)]); + $liveResults = collect([(new UncachedAuthor)->with('books.publisher') + ->first()]); $this->assertEmpty($authors->diffAssoc($cachedResults)); $this->assertEmpty($liveResults->diffAssoc($cachedResults)); @@ -443,7 +437,7 @@ public function testNestedRelationshipEagerloading() public function testLazyLoadedRelationshipResolvesThroughCachedBuilder() { $books = (new Author)->first()->books; - $key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1'; + $key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_notnull'; $tags = [ 'genealabslaravelmodelcachingtestsfixturesbook', ]; @@ -458,7 +452,7 @@ public function testLazyLoadedRelationshipResolvesThroughCachedBuilder() public function testLazyLoadingOnResourceIsCached() { $books = (new AuthorResource((new Author)->first()))->books; - $key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1'; + $key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_notnull'; $tags = [ 'genealabslaravelmodelcachingtestsfixturesbook', ];