Sha256: 9ea0f69fde7288416bbf8c22f9f6990d47c98de958273795195fe45ce395c333

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require "active_record/relation"
require "active_record/version"

module ActiveRecord
  module ConnectionAdapters
    module SQLServer
      module CoreExt
        module FinderMethods
          private

          def construct_relation_for_exists(conditions)
            if klass.connection.sqlserver?
              _construct_relation_for_exists(conditions)
            else
              super
            end
          end

          # Same as original except we order by values in distinct select if present.
          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
        end
      end
    end
  end
end

ActiveSupport.on_load(:active_record) do
  ActiveRecord::Relation.include(ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::FinderMethods)
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-7.1.11 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.10 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.9 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.8 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.7 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.6 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.5 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.4 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.3 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.2 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.1 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.0 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.0.rc2 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.0.rc1 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
activerecord-sqlserver-adapter-7.1.0.beta1 lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb