Module: RbPager::ActiveRecord::ActiveRecordRelationMethods
- Defined in:
- lib/rb_pager/orm/active_record_relation_methods.rb
Instance Method Summary collapse
- #left_over? ⇒ Boolean
-
#total_size(column_name = :all) ⇒ Object
Returns number of records that exist in scope of the current cursor.
Instance Method Details
#left_over? ⇒ Boolean
4 5 6 7 8 9 |
# File 'lib/rb_pager/orm/active_record_relation_methods.rb', line 4 def left_over? @left_over ||= begin # Cache #size otherwise multiple calls to the database will occur. records.size.positive? && records.size < total_size end end |
#total_size(column_name = :all) ⇒ Object
Returns number of records that exist in scope of the current cursor
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rb_pager/orm/active_record_relation_methods.rb', line 12 def total_size(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_size ||= begin context = except(:offset, :limit, :order) # Remove includes only if they are irrelevant context = context.except(:includes) unless references_eager_loaded_tables? args = [column_name] # .group returns an OrderedHash that responds to #count context = context.count(*args) if context.is_a?(Hash) || context.is_a?(ActiveSupport::OrderedHash) context.count else context.respond_to?(:count) ? context.count(*args) : context end end end |