Sha256: efd4e0cd3670367acbd2bcf3e775a7578b6209cfc6b22cd803d592dade301d43

Contents?: true

Size: 538 Bytes

Versions: 5

Compression:

Stored size: 538 Bytes

Contents

require 'active_record/precount/reflection_checker'

module ActiveRecord
  module Precount
    module CollectionProxyExtension
      def count(*args)
        return super if args.present?

        counter_name = :"#{@association.reflection.name}_count"
        if ReflectionChecker.count_loaded?(@association.owner, counter_name)
          @association.owner.association(counter_name).target
        else
          super
        end
      end
    end
  end

  Associations::CollectionProxy.prepend(Precount::CollectionProxyExtension)
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-precount-0.7.0 lib/active_record/precount/collection_proxy_extension.rb
activerecord-precount-0.7.0.beta1 lib/active_record/precount/collection_proxy_extension.rb
activerecord-precount-0.6.3 lib/active_record/precount/collection_proxy_extension.rb
activerecord-precount-0.6.2 lib/active_record/precount/collection_proxy_extension.rb
activerecord-precount-0.6.1 lib/active_record/precount/collection_proxy_extension.rb