Last active
August 8, 2019 07:37
-
-
Save yancya/fcaab41d197a0693499d7b40f149594d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROOMS = ['a', 'b'] | |
rooms_order = ROOMS.map.with_index { |r, i| "WHEN '#{r}' THEN #{i} " }.join.yield_self { |s| "CASE room #{s} END"} | |
Topic.where(room: ROOMS).order(rooms_order) | |
#=> SELECT "topics".* FROM "topics" WHERE "topics"."room" IN ('a', 'b') ORDER BY CASE room WHEN 'a' THEN 0 WHEN 'b' THEN 1 END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment