I’ve got this bit of code that basically tries to use a SQL case statement in the active relation order method:
relation = Foo.order("CASE WHEN foos.thing IS NOT NULL THEN 0 ELSE 1 END ASC")
and in the generated (and executed) SQL it comes up as:
(ORDER BY CASE ASC)
I’ve tried digging down into the source and lose the thread down in the visitor.access call. Is this a known issue? Is it user error? Is there some magical thing I have to do to make it happen? I was under the impression that it just inserted the raw SQL. There are other things we’re doing with the relation, such as select, limit, offset, group, having and joins.
help! 🙂
I’ve had this problem too:
You can put the CASE into the SELECT and name it so you can use it in the ORDER BY.