module ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::FinderMethods

Private Instance Methods

construct_relation_for_exists(conditions) click to toggle source

Same as original except we order by values in distinct select if present.

# File lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb, line 13
def construct_relation_for_exists(conditions)
  if distinct_value && offset_value
    relation = limit!(1)

    if select_values.present?
      relation = relation.order(*select_values)
    else
      relation = relation.except(:order)
    end
  else
    relation = except(:select, :distinct, :order)._select!(::ActiveRecord::FinderMethods::ONE_AS_ONE).limit!(1)
  end

  case conditions
  when Array, Hash
    relation.where!(conditions) unless conditions.empty?
  else
    relation.where!(primary_key => conditions) unless conditions == :none
  end

  relation
end