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.
Anyway I’m not sure how to find out if order_values is actual public API. It is generated method (source - https://github.com/rails/rails/blob/cb6db15d221d261bf5060c8752ba3b8b28e3b651/activerecord/lib/active_record/relation/query_methods.rb#L77) and it is not visible at https://api.rubyonrails.org/. But it doesn’t seems for me since it also returns array of arel nodes.
I had an idea to contribute “order?” or “ordered?” to public API to be able to find out if relation is already ordered.
I have two questions:
Is order_values public API and safe to use in our Rails application? If so, is there any way how to make it documented?
If not, would be order? or ordered? method welcomed as new query method? Implementation is really simple.