Skip to content
Browse files

- added documentation for dm-aggregates aggregate-function (multiple …

…aggregates + order by)
  • Loading branch information...
1 parent abe318d commit fd79b5cd0f0fc3d7a8fb7ed44962962d32c575aa @Ragmaanir Ragmaanir committed
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 fd79b5c

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