Sha256: c76c0a9e7ea0cc91ee40dc9161e8d8442a0ce3fb1dc6448ca413ec67b949bf57

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

module Kaminari
  module ActiveRecordRelationMethods
    # a workaround for AR 3.0.x that returns 0 for #count when page > 1
    # if +limit_value+ is specified, load all the records and count them
    if ActiveRecord::VERSION::STRING < '3.1'
      def count(column_name = nil, options = {}) #:nodoc:
        limit_value && !options[:distinct] ? length : super(column_name, options)
      end
    end

    def entry_name
      model_name.human.downcase
    end

    def reset #:nodoc:
      @total_count = nil
      super
    end

    def total_count(column_name = :all, options = {}) #:nodoc:
      # #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
      @total_count ||= begin
        c = except(:offset, :limit, :order)

        # Remove includes only if they are irrelevant
        c = c.except(:includes) unless references_eager_loaded_tables?

        # Rails 4.1 removes the `options` argument from AR::Relation#count
        args = [column_name]
        args << options if ActiveRecord::VERSION::STRING < '4.1.0'

        # .group returns an OrderdHash that responds to #count
        c = c.count(*args)
        if c.is_a?(Hash) || c.is_a?(ActiveSupport::OrderedHash)
          c.count
        else
          c.respond_to?(:count) ? c.count(*args) : c
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 6 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/kaminari-0.17.0/lib/kaminari/models/active_record_relation_methods.rb
kaminari-0.17.0 lib/kaminari/models/active_record_relation_methods.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/kaminari-0.16.3/lib/kaminari/models/active_record_relation_methods.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/kaminari-0.16.3/lib/kaminari/models/active_record_relation_methods.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/kaminari-0.16.3/lib/kaminari/models/active_record_relation_methods.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/kaminari-0.16.3/lib/kaminari/models/active_record_relation_methods.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/kaminari-0.16.3/lib/kaminari/models/active_record_relation_methods.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/kaminari-0.16.3/lib/kaminari/models/active_record_relation_methods.rb
kaminari-0.16.3 lib/kaminari/models/active_record_relation_methods.rb
kaminari-0.16.2 lib/kaminari/models/active_record_relation_methods.rb