Sha256: a61fd3f81c484c612fcc0567287566a1a801e66bb568782f3c30b60463670771

Contents?: true

Size: 704 Bytes

Versions: 4

Compression:

Stored size: 704 Bytes

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

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
composite_primary_keys-5.0.14 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-5.0.13 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-5.0.12 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-5.0.11 lib/composite_primary_keys/relation/query_methods.rb