Sha256: 5034fdafb5f287ee49634b680d6daebba7898f3c4fc982ea450977f204ab6f43

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'active_record/relation'
require 'active_record/version'

module ActiveRecord
  module ConnectionAdapters
    module SQLServer
      module CoreExt
        module Calculations
          private

          def build_count_subquery(relation, column_name, distinct)
            relation.select_values = [
              if column_name == :all
                distinct ? table[Arel.star] : Arel.sql(FinderMethods::ONE_AS_ONE)
              else
                column_alias = Arel.sql("count_column")
                aggregate_column(column_name).as(column_alias)
              end
            ]

            subquery = relation.arel.as(Arel.sql("subquery_for_count"))
            select_value = operation_over_aggregate_column(column_alias || Arel.star, "count", false)

            Arel::SelectManager.new(subquery).project(select_value)
          end
        end
      end
    end
  end
end

ActiveSupport.on_load(:active_record) do
  if ActiveRecord::VERSION::MAJOR == 5 &&
     ActiveRecord::VERSION::MINOR == 1 &&
     ActiveRecord::VERSION::TINY >= 4
    mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::Calculations
    ActiveRecord::Relation.prepend(mod)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-5.1.6 lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb
activerecord-sqlserver-adapter-5.1.5 lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb
activerecord-sqlserver-adapter-5.1.2 lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb