I’ve got a comments table, and each comment has a status like “approved”, “awaiting moderation”, “hidden”. When I show the comments I want them to be sorted according to their statuses – “approved”, then “awaiting moderation”, then “hidden”. I can do that with UNIONs but that’s a poor solution performance-wise.
I wonder if there’s a Doctrine2 equivalent for “ORDER BY (status <> ‘hidden’) DESC”? I know about ordering by calculated fields ( Can Doctrine2 @OrderBy a calculated field?) but I don’t see how to apply it here.
Did you resolve this issue? Another way you can do it, is do an sql query by where you give values to the status, and order by that if you want.
$conn = $entity_manager->getConnection();
$stmt = $conn->query(”
select
d.*, case status when ‘approved’ then 1
when ‘awaiting moderation’ then 2
when ‘hidden’ then 3 end sequence
from table order by sequence
“);
Just loop threw them.