Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

SQL error

Hello , so i have a problem with the Query() method , seems like the groupBy() is not working , any one knows why is that ? If i remove the groupBy() the sql functions normaly. I'm using Phalcon 2.0.0. and php gives the following error :

Fatal error: Call to undefined method Phalcon\Mvc\Model\Criteria::groupBy()


SELECT
  departments.department,
  count(department_members.department) as count

FROM departments

LEFT JOIN department_members on department_members.department = departments._

GROUP BY departments._

ORDER BY departments.department

$departments = Departments::query()
->columns([
  'Manager\Models\Departments._',
  'Manager\Models\Departments.department',
  'COUNT(Manager\Models\DepartmentMembers.department) as count',
])
->leftJoin('Manager\Models\DepartmentMembers', 'Manager\Models\DepartmentMembers.department = Manager\Models\Departments._')
->groupBy("Manager\Models\Departments._")
->orderBy("Manager\Models\Departments.department ASC")
->execute();


114.4k
Accepted
answer
Added groupBy/getGroupBy/having/getHaving to Mvc\Model\Criteria

In 2.0.4, just update phalcon to latest version, like 2.0.13 or 2.1.x

Also if i can sugest you - use queryBuilder - it gives you ability to use aliases so you don't need to type full namespaces. Also there are namespace aliases which you can register in modelsManager.

Also if i can sugest you - use queryBuilder - it gives you ability to use aliases so you don't need to type full namespaces. Also there are namespace aliases which you can register in modelsManager.

Please , how can i do that ? I really need to remove the namespaces