Rails 7 has bought in many upgrades to the
in_order_of method the past year.
From adding it to
to porting over to
the method has proved to be very useful.
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.
because this functionality is built into MySQL in the form of the
that connection adapter will generate the following SQL
So many inconsistencies!
Rails now drops records not listed in QueryMethods#in_order_of.
A clever and simple fix using SQL’s built-in