I’m facing problem where I need to check if active record relation is already ordered and if not I would like to order by some default column (id in my case).
Right now I’m using “scope.order_values.any?” to find out current ordering state and decide if we need to specify ordering or not.
I do not think this is a good idea to add to the framework. I can imagine “ordered” as a scope on models in various applications.
You can add it your ApplicationRecord.
There are good reasons for keeping APIs footprint small and not adding unnecessary public methods, even if they may be easy to implement. So before talking implementation, maybe making a strong case for why this `ordered?` would be a good addition to the Rails API would help your idea get traction.
So like others I must ask: why do you need this? I tried to think of some use cases, but all of them could be achieved by, instead of trying to add a default order after your query is mostly built, by setting the default order first, then reordering later when the code calls for it. This way, if your conditional logic did not reorder, the default order makes it through.
Also, I am not convinced the implementation, or even the definition of this `ordered?` method is that easy. It may be for the simple single model query case. But now throw in some relations, joins and includes, some of these ordered, some others not. What should `ordered?` return?