Sha256: b422873d5e83a89ecd1b51d4f11beb944c209de3c9fb961b4f17f0d4d784567d

Contents?: true

Size: 471 Bytes

Versions: 4

Compression:

Stored size: 471 Bytes

Contents

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

        counter_name = :"#{@association.reflection.name}_count"
        owner        = @association.owner

        if owner.class.has_reflection?(counter_name) && owner.association(counter_name).loaded?
          owner.association(counter_name).target
        else
          super(*args)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-precount-0.5.1 lib/active_record/precount/collection_proxy_extension.rb
activerecord-precount-0.5.0 lib/active_record/precount/collection_proxy_extension.rb
activerecord-precount-0.4.3 lib/active_record/precount/collection_proxy_extension.rb
activerecord-precount-0.4.2 lib/active_record/precount/collection_proxy_extension.rb