diff --git a/src/GroupModel.php b/src/GroupModel.php index 30d292d..cd665f9 100644 --- a/src/GroupModel.php +++ b/src/GroupModel.php @@ -92,6 +92,8 @@ public function groupBy($group, $aggregate = []) foreach ($aggregate as $field=>$expr) { + + //$this->addField($field); // field originally defined in the parent model $field_object = $this->master_model->hasField($field); // use hasField here! @@ -173,6 +175,9 @@ public function addGrouping(Query $query) $query->group($this->expr($field)); } } + + + } /** @@ -200,12 +205,7 @@ public function setLimit($count, $offset = null) * * @todo Incorrect implementation */ - public function setOrder($field, $desc = null) - { - $this->master_model->setOrder($field, $desc); - return $this; - } /** * Set action. @@ -253,6 +253,8 @@ public function action($mode, $args = []) $this->hook('afterGroupSelect', [$query]); + $query = $this->orderByQuery($query); + return $query; case 'count': @@ -307,6 +309,32 @@ public function action($mode, $args = []) return $query; } + /** + * Applies Order By to the query + * + */ + function orderByQuery($query) + { + + if ($this->order) { + + foreach ($this->order as $o) { + + if(is_string($o[1])){ + $query->order($o[0]." ".$o[1]); + } else { + $query->order($o[0],$o[1]); + } + } + } + + return $query; + + } + + + + /** * Our own way applying conditions, where we use "having" for * fields