Skip to content

Commit ce2f023

Browse files
authored
Merge pull request #10 from GeneaLabs/laravel-5.5
Laravel 5.5
2 parents 21ffa23 + 54140af commit ce2f023

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.5] - 2017-10-04
8+
### Fixed
9+
- parsing of nested, exists, raw, and column where clauses.
10+
711
## [0.2.4] - 2017-10-03
812
### Added
913
- .gitignore file to reduce download size for production environment.

src/CachedBuilder.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,27 @@ protected function getQueryColumns(array $columns) : string
7171
return '_' . implode('_', $columns);
7272
}
7373

74-
protected function getWhereClauses() : string
74+
protected function getWhereClauses(array $wheres = []) : string
7575
{
76-
return collect($this->query->wheres)->reduce(function ($carry, $where) {
76+
$wheres = collect($wheres);
77+
78+
if ($wheres->isEmpty()) {
79+
$wheres = collect($this->query->wheres);
80+
}
81+
82+
return $wheres->reduce(function ($carry, $where) {
83+
if (in_array($where['type'], ['Exists', 'Nested'])) {
84+
return $this->getWhereClauses($where['query']->wheres);
85+
}
86+
87+
if ($where['type'] === 'Column') {
88+
return "_{$where['boolean']}_{$where['first']}_{$where['operator']}_{$where['second']}";
89+
}
90+
91+
if ($where['type'] === 'raw') {
92+
return "_{$where['boolean']}_" . str_slug($where['sql']);
93+
}
94+
7795
$value = array_get($where, 'value');
7896

7997
if (in_array($where['type'], ['In', 'Null', 'NotNull'])) {

tests/Unit/CachedBuilderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,28 @@ public function testLazyLoadingOnResourceIsCached()
463463
$this->assertEmpty($books->diffAssoc($cachedResults));
464464
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
465465
}
466+
467+
public function testNestedRelationshipWhereClauseParsing()
468+
{
469+
// -> with('modelA.modelB')
470+
$this->markTestIncomplete();
471+
}
472+
473+
public function testExistsRelationshipWhereClauseParsing()
474+
{
475+
// ->whereHas(...)
476+
$this->markTestIncomplete();
477+
}
478+
479+
public function testColumnsRelationshipWhereClauseParsing()
480+
{
481+
// ???
482+
$this->markTestIncomplete();
483+
}
484+
485+
public function testRawWhereClauseParsing()
486+
{
487+
// ->whereRaw(...)
488+
$this->markTestIncomplete();
489+
}
466490
}

0 commit comments

Comments
 (0)