8.4.4: Doctrine Integrity constraint violation: 1052 Column in where clause is ambiguous

Permalink
I have 2 tables: Groups and Categories, where
/**
* One Group has many Categories
* @ORM\OneToMany(targetEntity="ClassifiedCategory",mappedBy="group_name",cascade={"persist"}))
*/
/**
* Many Categories have one Group
* @ORM\ManyToOne(targetEntity="ClassifiedGroup")
* @ORM\JoinColumn(name="group_name",referencedColumnName="group_id",onDelete="SET NULL")
*/

My Category List:
public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
{
    switch ($this->sortBy) {
        case "group_name":
            $query->leftJoin('c', 'ClassifiedGroups', 'j', 'j.group_id = c.group_name');
            $query->orderBy('j.group_name', $this->getSortByDirection());
            break;
        case "group_name_asc":
            $query->leftJoin('c', 'ClassifiedGroups', 'j', 'j.group_id = c.group_name');
            $query->orderBy('j.group_name', 'asc');
            break;
        case "group_name_desc":
            $query->leftJoin('c', 'ClassifiedGroups', 'j', 'j.group_id = c.group_name');
            $query->orderBy('j.group_name', 'desc');
            break;

When I select a group and then try to sort by group (e.g. dashboard/classifieds/categories/9?ccm_order_by=group_name&ccm_order_by_direction=asc&ccm_cursor=), it gives me the following error:

Doctrine \ DBAL \ Exception \ NonUniqueFieldNameException
An exception occurred while executing 'SELECT count(distinct c.category_id) FROM ClassifiedCategories c LEFT JOIN ClassifiedGroups j ON j.group_id = c.group_name WHERE group_name = ? LIMIT 1' with params ["7"]: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'group_name' in where clause is ambiguous

When no group is selected (e.g. dashboard/classifieds/categories?ccm_order_by=group_name&ccm_order_by_direction=asc&ccm_cursor=), no error occurs, it filters by group fine.

What seems to be the problem?

Thank you.

linuxoid