Skip to content
Permalink
Browse files

Query::applyOptions should ignore null values.

Null values are often used when building dynamic query data to mean
that the key should be ignored.
  • Loading branch information...
markstory committed Nov 16, 2013
1 parent b4b1c22 commit 18e77865b7b9bf3c5404c1568aa1140ef187e88a
Showing with 15 additions and 1 deletion.
  1. +1 −1 Cake/ORM/Query.php
  2. +14 −0 Cake/Test/TestCase/ORM/QueryTest.php
@@ -539,7 +539,7 @@ public function applyOptions(array $options) {
];
foreach ($options as $option => $values) {
if (isset($valid[$option])) {
if (isset($valid[$option]) && isset($values)) {
$this->{$valid[$option]}($values);
} else {
$this->_options[$option] = $values;
@@ -919,6 +919,20 @@ public function testApplyOptions() {
$this->assertEquals($expected, $query->contain());
}
/**
* ApplyOptions should ignore null values.
*
* @return void
*/
public function testApplyOptionsIgnoreNull() {
$options = [
'fields' => null,
];
$query = new Query($this->connection, $this->table);
$query->applyOptions($options);
$this->assertEquals([], $query->clause('select'));
}
/**
* Tests getOptions() method
*

0 comments on commit 18e7786

Please sign in to comment.
You can’t perform that action at this time.