I have a TraitQuestion model that have a number of traits or answers - each of which has a value such as 1, 2, 3, or -3105 (for none of the above). I can't change these values because they are required for an external API.
I'd like to order them by the value, but when I do that, the answer with -3105 shows up at the top even though it says "None of the above":
Answer 4 = -3105
Answer 1 = 1
Answer 2 = 2
Answer 3 = 3
Any idea on how we could order this so that it's
1
2
3
-3105?
I'm pretty new to SQL but it seems like I should be able to do something like this:
@trait_question.traits.order('CASE WHEN value AS int > 0 then 1 ELSE 0 END')
But that doesn't work. Any ideas how I can adjust the order call SQL such that it would order them in the correct order?
EDIT: This is Postgresql 9.4.1 via Amazon AWS
@trait_question.traits.order('CASE WHEN value AS int > 0 then value ELSE value*(-1) END')