我的查询:
SELECT c FROM MyBundle:Category c ORDER BY c.name = 'Archive', c.createdAt DESC
我得到了
Error: Expected end of string, got '='
我希望所有条目按日期排序,但归档应该是最后一个。我有什么想法吗?
答案 0 :(得分:1)
这将按日期降序对记录进行排序,将存档记录保留在底部:
SELECT c
FROM MyBundle:Category c
ORDER BY case when c.name = 'Archive' then 2 else 1 end,
c.createdAt DESC
作为这个答案的扩展,我必须改变这一点才能使它与DQL一起使用:
SELECT c,
CASE WHEN c.name = 'Archive' THEN 2 ELSE 1 END AS HIDDEN sortCondition
FROM MyBundle:Category c ORDER BY sortCondition, c.createdAt DESC