8.4.2 How to sort column by names of referenced objects in Doctrine
Permalink
I can sort a column like this:
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.
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.
PS. Just found out I can join tables and do all sorts of cool stuff. Wow. Doctrine rocks!