lib/arid_cache/cache_proxy/utilities.rb
# Generate an ORDER BY clause that preserves the ordering of the ids in *ids*.
#
# The method we use depends on the database adapter because only MySQL
# supports the ORDER BY FIELD() function.  For other databases we use
# a CASE statement.
Generate an ORDER BY clause that preserves the ordering of the ids in *ids*.
The method we use depends on the database adapter because only MySQL
supports the ORDER BY FIELD() function.  For other databases we use
a CASE statement.
Generate an ORDER BY clause that preserves the ordering of the ids in * ids * . The method we use depends on the database adapter because only MySQL supports the ORDER BY FIELD () function . For other databases we use a CASE statement .
def order_by(ids, klass=nil)
        column = namespaced_column(:id, klass)
        if ids.empty?
          nil
        elsif ::ActiveRecord::Base.is_mysql_adapter?
          "FIELD(#{column},#{ids.join(',')})"
        else
          order = ''
          ids.each_index { |i| order << "WHEN #{column}=#{ids[i]} THEN #{i+1} " }
          "CASE " + order + " END"
        end
      end
def order_by ( ids , klass = nil ) column = namespaced_column ( :id , klass ) if ids . empty? nil elsif :: ActiveRecord :: Base . is_mysql_adapter? "FIELD(#{column},#{ids.join(',')})" else order = '' ids . each_index { | i | order << "WHEN #{column}=#{ids[i]} THEN #{i+1} " } "CASE " + order + " END" end end
Generate an ORDER BY clause that preserves the ordering of the ids in *ids*.
Generate an ORDER BY clause that preserves the ordering of the ids in * ids * .
ids
klass