diff --git a/CHANGELOG.md b/CHANGELOG.md index ebb05ea..21be263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.2.5] - 2017-10-04 +### Fixed +- parsing of nested, exists, raw, and column where clauses. + ## [0.2.4] - 2017-10-03 ### Added - .gitignore file to reduce download size for production environment. diff --git a/src/CachedBuilder.php b/src/CachedBuilder.php index 07a8e77..f01b59c 100644 --- a/src/CachedBuilder.php +++ b/src/CachedBuilder.php @@ -71,9 +71,27 @@ protected function getQueryColumns(array $columns) : string return '_' . implode('_', $columns); } - protected function getWhereClauses() : string + protected function getWhereClauses(array $wheres = []) : string { - return collect($this->query->wheres)->reduce(function ($carry, $where) { + $wheres = collect($wheres); + + if ($wheres->isEmpty()) { + $wheres = collect($this->query->wheres); + } + + return $wheres->reduce(function ($carry, $where) { + if (in_array($where['type'], ['Exists', 'Nested'])) { + return $this->getWhereClauses($where['query']->wheres); + } + + if ($where['type'] === 'Column') { + return "_{$where['boolean']}_{$where['first']}_{$where['operator']}_{$where['second']}"; + } + + if ($where['type'] === 'raw') { + return "_{$where['boolean']}_" . str_slug($where['sql']); + } + $value = array_get($where, 'value'); if (in_array($where['type'], ['In', 'Null', 'NotNull'])) { diff --git a/tests/Unit/CachedBuilderTest.php b/tests/Unit/CachedBuilderTest.php index a3afd12..99a30ff 100644 --- a/tests/Unit/CachedBuilderTest.php +++ b/tests/Unit/CachedBuilderTest.php @@ -463,4 +463,28 @@ public function testLazyLoadingOnResourceIsCached() $this->assertEmpty($books->diffAssoc($cachedResults)); $this->assertEmpty($liveResults->diffAssoc($cachedResults)); } + + public function testNestedRelationshipWhereClauseParsing() + { + // -> with('modelA.modelB') + $this->markTestIncomplete(); + } + + public function testExistsRelationshipWhereClauseParsing() + { + // ->whereHas(...) + $this->markTestIncomplete(); + } + + public function testColumnsRelationshipWhereClauseParsing() + { + // ??? + $this->markTestIncomplete(); + } + + public function testRawWhereClauseParsing() + { + // ->whereRaw(...) + $this->markTestIncomplete(); + } }