mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 22:32:40 +08:00
Fixes #16081: Fixed composite IN using just one column
This commit is contained in:
committed by
Alexander Makarov
parent
ebb5976a22
commit
b128ec85f4
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
||||
2.0.16 under development
|
||||
------------------------
|
||||
|
||||
- Bug #16081: Fixed composite IN using just one column (rugabarbo)
|
||||
- Bug #16926: Fix shell autocompletion (GHopperMSK)
|
||||
- Bug #15850: check basePath is writable on publish in AssetManager (Groonya)
|
||||
- Bug #16910: Fix messages sorting on extract (Groonya)
|
||||
|
||||
@ -50,13 +50,23 @@ class InConditionBuilder implements ExpressionBuilderInterface
|
||||
// ensure values is an array
|
||||
$values = (array) $values;
|
||||
}
|
||||
if ($column instanceof \Traversable || ((is_array($column) || $column instanceof \Countable) && count($column) > 1)) {
|
||||
return $this->buildCompositeInCondition($operator, $column, $values, $params);
|
||||
}
|
||||
|
||||
if (is_array($column)) {
|
||||
if (count($column) > 1) {
|
||||
return $this->buildCompositeInCondition($operator, $column, $values, $params);
|
||||
} else {
|
||||
$column = reset($column);
|
||||
}
|
||||
}
|
||||
|
||||
if ($column instanceof \Traversable) {
|
||||
if (iterator_count($column) > 1) {
|
||||
return $this->buildCompositeInCondition($operator, $column, $values, $params);
|
||||
} else {
|
||||
$column->rewind();
|
||||
$column = $column->current();
|
||||
}
|
||||
}
|
||||
|
||||
$sqlValues = $this->buildValues($expression, $values, $params);
|
||||
if (empty($sqlValues)) {
|
||||
@ -88,6 +98,15 @@ class InConditionBuilder implements ExpressionBuilderInterface
|
||||
$sqlValues = [];
|
||||
$column = $condition->getColumn();
|
||||
|
||||
if (is_array($column)) {
|
||||
$column = reset($column);
|
||||
}
|
||||
|
||||
if ($column instanceof \Traversable) {
|
||||
$column->rewind();
|
||||
$column = $column->current();
|
||||
}
|
||||
|
||||
foreach ($values as $i => $value) {
|
||||
if (is_array($value) || $value instanceof \ArrayAccess) {
|
||||
$value = isset($value[$column]) ? $value[$column] : null;
|
||||
|
||||
@ -1130,6 +1130,19 @@ abstract class QueryBuilderTest extends DatabaseTestCase
|
||||
'([[id]], [[name]]) IN ((:qp0, :qp1))',
|
||||
[':qp0' => 1, ':qp1' => 'oy'],
|
||||
],
|
||||
'composite in (just one column)' => [
|
||||
['in', ['id'], [['id' => 1, 'name' => 'Name1'], ['id' => 2, 'name' => 'Name2']]],
|
||||
'[[id]] IN (:qp0, :qp1)',
|
||||
[':qp0' => 1, ':qp1' => 2],
|
||||
],
|
||||
'composite in using array objects (just one column)' => [
|
||||
['in', new TraversableObject(['id']), new TraversableObject([
|
||||
['id' => 1, 'name' => 'Name1'],
|
||||
['id' => 2, 'name' => 'Name2'],
|
||||
])],
|
||||
'[[id]] IN (:qp0, :qp1)',
|
||||
[':qp0' => 1, ':qp1' => 2],
|
||||
],
|
||||
|
||||
// in using array objects.
|
||||
[['id' => new TraversableObject([1, 2])], '[[id]] IN (:qp0, :qp1)', [':qp0' => 1, ':qp1' => 2]],
|
||||
|
||||
Reference in New Issue
Block a user