it's a pretty complex question to explain using words, so I gonna use code:
Let's imagine the following scenario:
User.create name: "bar"
User.create name: "foo"
User.create name: "baz"
I want to perform the following query:
User.where(name: ["foo", "bar", "baz"])
User has no default_scope
I want to retrieve these 3 records in the following order:
<User name:foo>, <User name:bar>, <User name:baz>
But, as you may know, rails will return the records in the same order as they were created (Actually I do believe it is the database behavior, rails is just a proxy). Like the next snippet:
<User name:bar>, <User name:foo>, <User name:baz>
Anyway, Does anyone know if there is a clean way to solve it?
I could use an each and perform the query but it'll end up in an N+1 query and I want to avoid it.