Created
August 8, 2019 06:57
-
-
Save yancya/ee5a87b8c25502ac0faa2dc3dccd19c3 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_table = ROOMS.map.with_index { |r, i| "('#{r}',#{i})" }.join(',').yield_self { |s| "(VALUES#{s}) as rooms(room, room_order)" } | |
Topic.joins("join #{rooms_table} using(room)").order(:room_order) | |
#=> SELECT "topics".* FROM "topics" join (VALUES('a',0),('b',1)) as rooms(room, room_order) using(room) ORDER BY "room_order" ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment