Sha256: c7736d1a9c6cda681e127fbb78a888100791cb7a14e36c92ae5d76bc10276ab9

Contents?: true

Size: 651 Bytes

Versions: 17

Compression:

Stored size: 651 Bytes

Contents

module ActiveRecord
  module QueryMethods
    def reverse_order
      order_clause = arel.order_clauses.join(', ')
      relation = except(:order)

      # CPK
      # order = order_clause.blank? ?
      #  "#{@klass.table_name}.#{@klass.primary_key} DESC" :
      #  reverse_sql_order(order_clause)

      order = unless order_clause.blank?
        reverse_sql_order(order_clause)
      else
        primary_keys = composite? ? @klass.primary_keys : [@klass.primary_key]
        primary_keys.map do |key|
          "#{@klass.table_name}.#{key} DESC"
        end.join(", ")
      end

      relation.order Arel::SqlLiteral.new order
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
composite_primary_keys-3.1.11 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.10 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.9 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.8 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.7 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.6 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.5 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.4 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.2 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.1 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.1.0 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.0.9 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.0.8 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.0.7 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.0.4 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.0.3 lib/composite_primary_keys/query_methods.rb
composite_primary_keys-3.0.0.b3 lib/composite_primary_keys/query_methods.rb