Rails 7 has bought in many upgrades to the in_order_of method the past year.
From adding it to
Enumerable
to porting over to
ActiveRecord,
the method has proved to be very useful.
Before
However,
there are still some quirks.
Let’s look at the enumerable example.
It drops records not part of the order list.
Let’s look at an ActiveRecord example.
So this does not drop records not part of the list!
This can cause many inconsistencies in working.
It is because internally, the query method generates relevant SQL using CASE statements.
However,
because this functionality is built into MySQL in the form of the
FIELD function,
that connection adapter will generate the following SQL
instead: