8.4.2 How to sort column by names of referenced objects in Doctrine

Permalink
I can sort a column like this:
protected $autoSortColumns = [
    'c.category',
];
public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
{
    $query->orderBy('category', 'asc');
    return $query;
}

assuming the 'category' column has string values.

But what if the 'category' contain objects referenced with another table containing the category strings. In this case the 'category' will have IDs of those objects instead of strings. Is it possible to sort the first table anyhow? If I do the above, it sorts by the category IDs obviously. I want to sort by category names.

Thank you.

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
This seems to be what I need:
$query->leftJoin('c', 'CategoriesTable', 'm', 'm.category_id = c.category');
$query->orderBy('m.category', 'asc');


PS. Just found out I can join tables and do all sorts of cool stuff. Wow. Doctrine rocks!