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 22
def _construct_relation_for_exists(conditions)
  conditions = sanitize_forbidden_attributes(conditions)

  if distinct_value && offset_value
    # Start of monkey-patch
    if select_values.present?
      relation = order(*select_values).limit!(1)
    else
      relation = except(:order).limit!(1)
    end
    # End of monkey-patch
  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
construct_relation_for_exists(conditions) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb, line 13
def construct_relation_for_exists(conditions)
  if klass.connection.sqlserver?
    _construct_relation_for_exists(conditions)
  else
    super
  end
end