Wazery
Wazery

Reputation: 15863

Rails where with array returned data order

I just want to make sure that if I used a where query like so:

product1, product2 = Product.where(id: [1, 2]) it will always return the data in that order specified in the array, so the assignment will always be correct.

Is that the behaviour or it might not return the data in that specific order at some time?

Upvotes: 0

Views: 219

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52357

Records will always be fetched from database in ascending order by id column (unless you specify another order).

So yea, this is the behavior and you'll always get the assignment right here.

Upvotes: 2

Related Questions