Skip to content

Commit

Permalink
Adding support for a single ExpressionInterface as the value for
Browse files Browse the repository at this point in the history
a TupleComparison
  • Loading branch information
lorenzo committed Jan 12, 2014
1 parent 9b92cc8 commit c2ddf76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Cake/Database/Expression/TupleComparison.php
Expand Up @@ -66,7 +66,13 @@ public function sql(ValueBinder $generator) {
*/
protected function _stringifyValues($generator) {
$values = [];
foreach ($this->getValue() as $i => $value) {
$parts = $this->getValue();

if ($parts instanceof ExpressionInterface) {
return $parts->sql($generator);
}

foreach ($parts as $i => $value) {
if ($value instanceof ExpressionInterface) {
$values[] = $value->sql($generator);
continue;
Expand Down
13 changes: 13 additions & 0 deletions Test/TestCase/Database/Expression/TupleComparisonTest.php
Expand Up @@ -123,4 +123,17 @@ public function testTraverse() {
$this->assertSame($value1, $expressions[2]);
}

/**
* Tests that a single ExpressionInteface can be used as the value for
* comparison
*
* @return void
*/
public function testValueAsSingleExpression() {
$value = new QueryExpression('SELECT 1, 1');
$f = new TupleComparison(['field1', 'field2'], $value);
$binder = new ValueBinder;
$this->assertEquals('(field1, field2) = (SELECT 1, 1)', $f->sql($binder));
}

}

0 comments on commit c2ddf76

Please sign in to comment.