Sha256: 4eefd6770ff6b984d02e126abc40b189b83ab11aee79be579483b519e97662fb

Contents?: true

Size: 773 Bytes

Versions: 2

Compression:

Stored size: 773 Bytes

Contents

module Kaminari
  module ActiveRecordRelationMethods
    extend ActiveSupport::Concern
    module InstanceMethods
      # 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 Rails.version < '3.1'
        def count #:nodoc:
          limit_value ? length : super
        end
      end

      def total_count #: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
        c = except(:offset, :limit, :includes, :order).count
        # .group returns an OrderdHash that responds to #count
        c.respond_to?(:count) ? c.count : c
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kaminari-0.12.1 lib/kaminari/models/active_record_relation_methods.rb
kaminari-0.12.0 lib/kaminari/models/active_record_relation_methods.rb