Skip to content

Instantly share code, notes, and snippets.

@raghubetina
Last active August 4, 2019 17:44
Show Gist options
  • Save raghubetina/add847e3b29cd198db8eb7e34e526d16 to your computer and use it in GitHub Desktop.
Save raghubetina/add847e3b29cd198db8eb7e34e526d16 to your computer and use it in GitHub Desktop.
implicit_order

Rails 6's implicit_order_column is great but wouldn't it be even more great if it worked for more than just finders (e.g. first, last)? It's reasonable to expect, after declaring an implicit order column, for it to also be in effect when using other methods (e.g. all, take, pluck, each, associations) — but it is not.

IMO default_scope is not really a substitute, either, unless you want everyone else to always have to remember to call .reorder if a different order is needed. In my view, scope is more of a filtering thing than an ordering thing anyway, and I always wish there had been an analogous order macro.

I think implicit_order is needed (taking a block, not just a column name, so that direction or joins, etc, can be specified). As soon as a different .order is called, this one should be dropped entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment