HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/default/doc/activerecord-6.1.4.1/ri/ActiveRecord/Calculations/calculate-i.ri
U:RDoc::AnyMethod[iI"calculate:ETI")ActiveRecord::Calculations#calculate;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;	[I"_This calculates aggregate values in the given column. Methods for #count, #sum, #average, ;TI"9#minimum, and #maximum have been added as shortcuts.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim;	[I"?Person.calculate(:count, :all) # The same as Person.count
;TI";Person.average(:age) # SELECT AVG(age) FROM people...
;TI"
;TI"A# Selects the minimum age for any family without any minors
;TI"DPerson.group(:last_name).having("min(age) > 17").minimum(:age)
;TI"
;TI"Person.sum("2 * age")
;T:@format0o;
;	[I")There are two basic forms of output:;T@o:RDoc::Markup::List:
@type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;	[o;
;	[I"WSingle aggregate value: The single value is type cast to Integer for COUNT, Float ;TI">for AVG, and the given column's type for everything else.;T@o;;0;	[o;
;	[I"TGrouped values: This returns an ordered hash of the values and groups them. It ;TI"Itakes either a column name, or the name of a belongs_to association.;T@o;;	[I"6values = Person.group('last_name').maximum(:age)
;TI"puts values["Drake"]
;TI"
# => 43
;TI"
;TI"1drake  = Family.find_by(last_name: 'Drake')
;TI"Nvalues = Person.group(:family).maximum(:age) # Person belongs_to :family
;TI"puts values[drake]
;TI"
# => 43
;TI"
;TI"&values.each do |family, max_age|
;TI"  ...
;TI"end;T;
0:
@fileI"/lib/active_record/relation/calculations.rb;T:0@omit_headings_from_table_of_contents_below000[I"(operation, column_name);T@8FI"Calculations;TcRDoc::NormalModule00