Doctrine 2 mysql FIELD function in order by

前端 未结 4 802
轮回少年
轮回少年 2020-11-29 11:08

I\'m trying to use the MySQL FIELD function in an order by clause in a query. I\'m assuming that Doctrine 2 doesn\'t support the FIELD function out of the box - is that true

4条回答
  •  余生分开走
    2020-11-29 12:02

    In case that the field that you want to "order by" is an ENUM data type, then ORDER BY will work in the order in which the values were defined for that ENUM field.

    For example, I had a filed defined as enum('n','pe','o','ap','c') that was giving a weird ordering. The ordering got fixed after updating the enum to: enum('ap','c','n','o','pe')

提交回复
热议问题