Commit 1ea895e2 by Ivan Pomortsev

Update QueryBuilder.php

Fixed some errors – syntax with ";" after closure function and also moved building of unions queries into this function.
parent 12cbaf90
...@@ -741,27 +741,27 @@ class QueryBuilder extends \yii\base\Object ...@@ -741,27 +741,27 @@ class QueryBuilder extends \yii\base\Object
} }
/** /**
* @param string $left left element of reducing pair * @param Query $left left element of reducing pair
* @param string $right right element of reducing pair * @param Query $right right element of reducing pair
* @return string imploding pair with "UNION ALL" if * @return string imploding pair with "UNION ALL" if
* right element is array and "UNION" if not * right element is array and "UNION" if not
*/ */
$reducer = function($left, $right) $reducer = function($left, $right)
{ {
if($all = is_array($right)) $all = $right->params['all'];
list ($right) = $right; list($right, $params) = $this->build($right);
return $left . ' UNION ' . ($all ? 'ALL ' : ' ') . $right . ' ) '; return $left . ' UNION ' . ($all ? 'ALL ' : ' ') . $right . ' ) ';
} };
foreach ($unions as $i => $union) { foreach ($unions as $i => $union) {
if ($union instanceof Query) { if ($union instanceof Query) {
// 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], $params) = $this->build($union);
$union->params = $originalParams; $union->params = $originalParams;
} }
} }
return array_reduce($unions, $reducer); return array_reduce($unions, $reducer);
} }
......
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