Monkey patch a prepend_order method

This commit is contained in:
Jorge Manrubia
2025-04-11 10:28:12 +02:00
parent 4f3f322528
commit 17aa9b97e9
2 changed files with 17 additions and 6 deletions
+16
View File
@@ -0,0 +1,16 @@
module ActiveRecordRelationPrependOrder
extend ActiveSupport::Concern
included do
def prepend_order(*args)
new_orders = args.flatten.map { |arg| arg.is_a?(String) ? arg : arg.to_sql }
spawn.tap do |relation|
relation.order_values = new_orders + order_values
end
end
end
end
ActiveRecord::Relation.include(ActiveRecordRelationPrependOrder)
ActiveRecord::AssociationRelation.include(ActiveRecordRelationPrependOrder)