Commit 7da3449d by Ivan Pomortsev

Update QueryBuilder.php

Change buildUnion method to be ready to accept parameters in <code>['all' => $all, 'query' => $query]</code> format for division to "UNION" and "UNION ALL" constructions.
parent 5f3d601b
...@@ -748,9 +748,14 @@ class QueryBuilder extends \yii\base\Object ...@@ -748,9 +748,14 @@ class QueryBuilder extends \yii\base\Object
*/ */
$reducer = function($left, $right) $reducer = function($left, $right)
{ {
$all = $right->params['all']; if(is_array($left))
list($right, $params) = $this->build($right); $left = $left['query'];
return $left . ' UNION ' . ($all ? 'ALL ' : ' ') . $right . ' )'; $all = false;
if(is_array($right)) {
$all = $right['all'];
$right = $right['query'];
}
return $left . ' UNION ' . ($all ? 'ALL ' : '') . '( ' . $right . ' )';
}; };
foreach ($unions as $i => $union) { foreach ($unions as $i => $union) {
...@@ -758,6 +763,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -758,6 +763,7 @@ class QueryBuilder extends \yii\base\Object
// save the original parameters so that we can restore them later to prevent from modifying the query object // save the original parameters so that we can restore them later to prevent from modifying the query object
$originalParams = $union->params; $originalParams = $union->params;
$union->addParams($params); $union->addParams($params);
list ($unions[$i]['query'], $params) = $this->build($query);
$union->params = $originalParams; $union->params = $originalParams;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment