0

Today I have an specific "issue" to solve with Kohana (3.3) orm order_by method. I need rewrite the order_by() method to accept anything like that:

->order_by("IF(ISNULL(foo) OR foo = '', 1, 0), foo", "ASC")

(This conditional put all null values in the end of query result). But, the orm escape the query with " ` " then it not work.

ORDER BY `IF(ISNULL(foo) OR foo = "", 1, 0), foo` ASC

I can mount this query using DB::query(), but I need use that conditional in all order_by query on my system.

4

1 回答 1

2

试试 DB::expr(),它的工作

->order_by(DB::expr("IF(ISNULL(foo) OR foo = '', 1, 0), foo"), "ASC")
于 2013-07-17T09:39:39.263 回答