Browse Source

Fix Expression parameter binding in 'And' clause

batch-query-test
CedricYii 9 years ago committed by SilverFire - Dmitry Naumenko
parent
commit
2bd14098f9
  1. 5
      framework/db/QueryBuilder.php
  2. 1
      tests/framework/db/QueryBuilderTest.php

5
framework/db/QueryBuilder.php

@ -1006,6 +1006,11 @@ class QueryBuilder extends \yii\base\Object
if (is_array($operand)) {
$operand = $this->buildCondition($operand, $params);
}
if ($operand instanceof Expression) {
foreach ($operand->params as $n => $v) {
$params[$n] = $v;
}
}
if ($operand !== '') {
$parts[] = $operand;
}

1
tests/framework/db/QueryBuilderTest.php

@ -216,6 +216,7 @@ class QueryBuilderTest extends DatabaseTestCase
// and
[ ['and', 'id=1', 'id=2'], '(id=1) AND (id=2)', [] ],
[ ['and', 'type=1', ['or', 'id=1', 'id=2']], '(type=1) AND ((id=1) OR (id=2))', [] ],
[ ['and', 'id=1', new Expression('id=:param1', [':param1' => 2])], '(id=1) AND (id=:param1)', [':param1' => 2] ],
// or
[ ['or', 'id=1', 'id=2'], '(id=1) OR (id=2)', [] ],

Loading…
Cancel
Save