Module: BetterAr::Calculations

Defined in:
lib/better_ar/calculations.rb

Instance Method Summary collapse

Instance Method Details

#count(column_name = nil, count_options = {}) ⇒ Integer

Does a count on the query

example:

User.count(:age => 20)

is the same as:

User.where(:age => 20).count

if the key :conditions is present it will fall back to legacy

Parameters:

  • Optional (Hash)

    follows same convention as #all

Returns:

  • (Integer)


16
17
18
19
20
21
22
23
# File 'lib/better_ar/calculations.rb', line 16

def count(column_name = nil, count_options = {})
  if column_name.is_a?(Hash)
    count_options = column_name.clone
    column_name = nil
  end

  all(count_options).calculate(:count, nil, {})
end