Module: BetterAr::Calculations

Defined in:
lib/better_ar/calculations.rb

Instance Method Summary collapse

Instance Method Details

#count(opts = {}, extra = {}) ⇒ 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
24
# File 'lib/better_ar/calculations.rb', line 16

def count(opts = {}, extra = {})
  if opts.nil? || opts.empty?
    super(nil, extra)
  elsif opts.key?(:conditions)
    super(opts, extra)
  else
    all(opts).count
  end
end