Sha256: dfff8812228d2ef64d26706d36f9370375c738904969d0b0d5ef886c2a28ea67

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

module CompositePrimaryKeys
  module ActiveRecord
    module QueryMethods
      def reverse_sql_order(order_query)
        if order_query.empty?
          # CPK
          # return [table[primary_key].desc] if primary_key

          if primary_key
            # break apart CPKs
            return primary_key.map do |key|
              table[key].desc
            end
          else
            raise IrreversibleOrderError,
                  "Relation has no current order and table has no primary key to be used as default order"
          end
        end

        order_query.flat_map do |o|
          order_query.flat_map do |o|
            case o
            when Arel::Attribute
              o.desc
            when Arel::Nodes::Ordering
              o.reverse
            when String
              if does_not_support_reverse?(o)
                raise IrreversibleOrderError, "Order #{o.inspect} can not be reversed automatically"
              end
              o.split(",").map! do |s|
                s.strip!
                s.gsub!(/\sasc\Z/i, " DESC") || s.gsub!(/\sdesc\Z/i, " ASC") || (s << " DESC")
              end
            else
              o
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
composite_primary_keys-13.0.8 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-14.0.6 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.7 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.6 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-14.0.5 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.5 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.4 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-14.0.4 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-14.0.3 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.3 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-14.0.2 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.2 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-14.0.1 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.1 lib/composite_primary_keys/relation/query_methods.rb
composite_primary_keys-13.0.0 lib/composite_primary_keys/relation/query_methods.rb