Module: Kaminari::ActiveRecordRelationMethods
- Defined in:
- lib/kaminari/models/active_record_relation_methods.rb
Instance Method Summary collapse
-
#count(column_name = nil, options = {}) ⇒ Object
:nodoc:.
- #entry_name ⇒ Object
-
#total_count(column_name = :all, options = {}) ⇒ Object
:nodoc:.
Instance Method Details
#count(column_name = nil, options = {}) ⇒ Object
:nodoc:
6 7 8 |
# File 'lib/kaminari/models/active_record_relation_methods.rb', line 6 def count(column_name = nil, = {}) #:nodoc: limit_value && ![:distinct] ? length : super(column_name, ) end |
#entry_name ⇒ Object
11 12 13 |
# File 'lib/kaminari/models/active_record_relation_methods.rb', line 11 def entry_name model_name.human.downcase end |
#total_count(column_name = :all, options = {}) ⇒ Object
:nodoc:
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kaminari/models/active_record_relation_methods.rb', line 15 def total_count(column_name = :all, = {}) #: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 << 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 |