Skip to content

Commit

Permalink
Merge pull request #5083 from cakephp/3.0-fix-comparison
Browse files Browse the repository at this point in the history
3.0 fix comparison
  • Loading branch information
markstory committed Nov 5, 2014
2 parents 135921a + be0866f commit fc18336
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Database/Expression/QueryExpression.php
Expand Up @@ -483,7 +483,11 @@ protected function _addConditions(array $conditions, array $types) {
continue;
}

if ($c instanceof self && count($c) > 0) {
if ($c instanceof self && count($c) === 0) {
continue;
}

if ($numericKey && $c instanceof ExpressionInterface) {
$this->_conditions[] = $c;
continue;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -502,4 +502,24 @@ public function testContainNoEmptyAssociatedObjects() {
$this->assertNull($result->user, 'No record should be null.');
}

/**
* Tests that using a comparison expression inside an OR condition works
*
* @see https://github.com/cakephp/cakephp/issues/5081
* @return void
*/
public function testOrConditionsWithExpression() {
$table = TableRegistry::get('Articles');
$query = $table->find();
$query->where([
'OR' => [
new \Cake\Database\Expression\Comparison('id', 1, 'integer', '>'),
new \Cake\Database\Expression\Comparison('id', 3, 'integer', '<')
]
]);

$results = $query->toArray();
$this->assertCount(3, $results);
}

}

0 comments on commit fc18336

Please sign in to comment.