Skip to content
Browse files

Merge pull request #25 from Ragmaanir/master

Extended aggregate-documentation to include multiple aggregates and order by
  • Loading branch information...
2 parents abe318d + fd79b5c commit c071ba32e5e20a4d8ebb248873355ca0fab86d28 @solnic solnic committed Oct 31, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 docs/find.md
View
15 docs/find.md
@@ -375,4 +375,19 @@ Friend.sum(:age) # returns total age of all friends
Friend.max(:age, :conditions => [ 'gender = ?', 'female' ]) # returns the total age of all female friends
{% endhighlight %}
+Multiple aggregates
+-------------------
+
+{% highlight ruby linenos %}
+sum, count = Friend.aggregate(:age.sum, :all.count) # returns the sum of all ages and the count of all friends
+{% endhighlight %}
+
+Aggregates with order-by
+------------------------
+
+{% highlight ruby linenos %}
+Friend.aggregate(:city, :all.count) # returns the city names and the number of friends living in each city
+# e.g. [['Hamburg', 3], ['New York', 4], ['Rome', 0], ... ]
+{% endhighlight %}
+
[DataMapper_Repository]:http://rubydoc.info/github/datamapper/dm-core/master/DataMapper/Repository

0 comments on commit c071ba3

Please sign in to comment.
Something went wrong with that request. Please try again.