I am searching for records using an IN query likes so:
Event.where("events.id IN (#{events.nil? ? '' : events.collect(&:id).join(',')})")
Which produces output like:
SELECT "events".* FROM "events" WHERE (events.id IN (143,169,139,48,172,146,145,124,111,49,108,18,113,144)) AND (status = 'live') LIMIT 10
However, this is then sorted by update_at by default. I'd like it to sort by the IN part of the query. What I mean is that I'd like this to be the order it returns in:
143,169,139,48,172,146,145,124,111,49,108,18,113,144
Is that possible at all?
I must also note that I can't add a priority column or similar to the table as the "events" part will be dynamically generated.
I've just discovered a very similar question here:
Postgres ORDER BY values in IN list using Rails Active Record
Feel free to mark this one of mine as duplicate