--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: This calculates aggregate values in the given column. Methods for count, sum, average, minimum, and maximum have been added as shortcuts. Options such as <tt>:conditions</tt>, <tt>:order</tt>, <tt>:group</tt>, <tt>:having</tt>, and <tt>:joins</tt> can be passed to customize the query.
- !ruby/struct:SM::Flow::P 
  body: "There are two basic forms of output:"
- !ruby/struct:SM::Flow::VERB 
  body: "  * Single aggregate value: The single value is type cast to Fixnum for COUNT, Float for AVG, and the given column's type for everything else.\n  * Grouped values: This returns an ordered hash of the values and groups them by the <tt>:group</tt> option.  It takes either a column name, or the name\n    of a belongs_to association.\n\n      values = Person.maximum(:age, :group =&gt; 'last_name')\n      puts values[&quot;Drake&quot;]\n      =&gt; 43\n\n      drake  = Family.find_by_last_name('Drake')\n      values = Person.maximum(:age, :group =&gt; :family) # Person belongs_to :family\n      puts values[drake]\n      =&gt; 43\n\n      values.each do |family, max_age|\n      ...\n      end\n"
- !ruby/struct:SM::Flow::P 
  body: "Options:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:conditions</tt> - An SQL fragment like &quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ]. See conditions in the intro.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "<tt>:include</tt>: Eager loading, see Associations for details. Since calculations don't load anything, the purpose of this is to access fields on joined tables in your conditions, order, or group clauses."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:joins</tt> - An SQL fragment for additional joins like &quot;LEFT JOIN comments ON comments.post_id = id&quot;. (Rarely needed). The records will be returned read-only since they will have attributes that do not correspond to the table's columns.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:order</tt> - An SQL fragment like &quot;created_at DESC, name&quot; (really only used with GROUP BY calculations).
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:group</tt> - An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:select</tt> - By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not include the joined columns.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:distinct</tt> - Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ...
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "Examples:"
- !ruby/struct:SM::Flow::VERB 
  body: "  Person.calculate(:count, :all) # The same as Person.count\n  Person.average(:age) # SELECT AVG(age) FROM people...\n  Person.minimum(:age, :conditions =&gt; ['last_name != ?', 'Drake']) # Selects the minimum age for everyone with a last name other than 'Drake'\n  Person.minimum(:age, :having =&gt; 'min(age) &gt; 17', :group =&gt; :last_name) # Selects the minimum age for any family without any minors\n  Person.sum(&quot;2 * age&quot;)\n"
full_name: ActiveRecord::Calculations::ClassMethods#calculate
is_singleton: false
name: calculate
params: (operation, column_name, options = {})
visibility: public
