aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Del Ben <oscar@oscardelben.com>2012-07-05 19:01:00 -0700
committerOscar Del Ben <oscar@oscardelben.com>2012-07-05 19:01:00 -0700
commitd7a2309fe39d3807c1c97de116b23d6bb2c08d79 (patch)
tree6a33417bf3c79d9ed2bc44985b1f01a0372a9e88
parentd203a0e0b4f2a1959fb3dc486a5ee6684b44ccb3 (diff)
downloadrails-d7a2309fe39d3807c1c97de116b23d6bb2c08d79.tar.gz
rails-d7a2309fe39d3807c1c97de116b23d6bb2c08d79.tar.bz2
rails-d7a2309fe39d3807c1c97de116b23d6bb2c08d79.zip
Add group documentation
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 51d21121c8..1636e49065 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -142,6 +142,18 @@ module ActiveRecord
self
end
+ # Allows to specify a group attribute:
+ #
+ # User.group(:name)
+ # => SELECT "users".* FROM "users" GROUP BY name
+ #
+ # Returns an array with uniq records based on the `group` attribute:
+ #
+ # User.select([:id, :name])
+ # => [#<User id: 1, name: "Oscar">, #<User id: 2, name: "Oscar">, #<User id: 3, name: "Foo">
+ #
+ # User.group(:name)
+ # => [#<User id: 3, name: "Foo", ...>, #<User id: 2, name: "Oscar", ...>]
def group(*args)
args.blank? ? self : spawn.group!(*args)
end