diff --git a/src/Query/GroupOption.php b/src/Query/GroupOption.php index 5afb03e..a5030ee 100644 --- a/src/Query/GroupOption.php +++ b/src/Query/GroupOption.php @@ -106,18 +106,15 @@ class GroupOption implements QueryOptionInterface, QueryOptionTreeItemInterface /** * {@inheritdoc} */ - public function apply($query, $original_query = NULL) { - if (is_null($original_query)) { - $original_query = $query; - } + public function apply($query, $parent_group = NULL) { switch ($this->conjunction) { case 'OR': - $group = $original_query->orConditionGroup(); + $group = $query->orConditionGroup(); break; case 'AND': default: - $group = $original_query->andConditionGroup(); + $group = $query->andConditionGroup(); break; } @@ -128,12 +125,18 @@ class GroupOption implements QueryOptionInterface, QueryOptionTreeItemInterface } if (!empty($this->childGroups)) { - $group = array_reduce($this->childGroups, function ($group, $child) use ($original_query) { - return $child->apply($group, $original_query); + $group = array_reduce($this->childGroups, function ($group, $child) use ($query) { + return $child->apply($query, $group); }, $group); } - return $query->condition($group); + // We are at the beginning of the tree and there is no parent group. + if (is_null($parent_group)) { + return $query->condition($group); + } + else { + return $parent_group->condition($group); + } } /**