Sha256: d488239b46490ed4ddd014a6c4212fdfb36dca2dee0a22f09a113690192b4f56

Contents?: true

Size: 766 Bytes

Versions: 1

Compression:

Stored size: 766 Bytes

Contents

module ActiveRecord
  module Precount
    module Builder
      module HasManyExtension
        def valid_options
          super + [:count_loader]
        end

        def build(model)
          define_count_loader(model) if options[:count_loader]
          super
        end

        def define_count_loader(model)
          name_with_count = :"#{name}_count"
          name_with_count = options[:count_loader] if options[:count_loader].is_a?(Symbol)

          valid_options = options.slice(*Associations::Builder::CountLoader.valid_options)
          reflection = Associations::Builder::CountLoader.build(model, name_with_count, scope, valid_options)
          Reflection.add_reflection(model, name_with_count, reflection)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-precount-0.5.1 lib/active_record/precount/has_many_extension.rb