Aggregatfunktionen von ActiveRecord 0

Posted by fwoeck
on Tuesday, October 28

Nicht vergessen: außer find, all, first, last, etc. gibt es natürlich auch die SQL-Aggregatfunktionen:

>> Voting.count
=> 379

>> Voting.sum(:points, :conditions => 'voter_id = 17')
=> 62

>> Voting.average(:points)
=> 3.5937

>> Voting.minimum(:points)
=> 1

>> Project.tasks.maximum(:duration, :conditions => 'complete = 1')
=> 5