Sha256: 9aff5407996a3948747e06dd2e518b5fc64645daa81c00b25dcafdf1db87dbe3
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
module CompositePrimaryKeys::ActiveRecord::QueryMethods def reverse_sql_order(order_query) # CPK # order_query = ["#{quoted_table_name}.#{quoted_primary_key} ASC"] if order_query.empty? # break apart CPKs order_query = primary_key.map do |key| "#{quoted_table_name}.#{connection.quote_column_name(key)} ASC" end if order_query.empty? order_query.map do |o| case o when Arel::Nodes::Ordering o.reverse when String, Symbol o.to_s.split(',').collect do |s| s.strip! s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') end else o end end.flatten end def order(*args) args.map! do |arg| if arg.is_a?(Arel::Nodes::Ordering) && arg.expr.name.is_a?(Array) arg = arg.expr.name.map do |key| cloned_node = arg.clone cloned_node.expr.name = key cloned_node end end arg end if composite? super(*args) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
composite_primary_keys-7.0.16 | lib/composite_primary_keys/relation/query_methods.rb |