diff options
author | Oscar Del Ben <oscar@oscardelben.com> | 2012-07-05 19:01:00 -0700 |
---|---|---|
committer | Oscar Del Ben <oscar@oscardelben.com> | 2012-07-05 19:01:00 -0700 |
commit | d7a2309fe39d3807c1c97de116b23d6bb2c08d79 (patch) | |
tree | 6a33417bf3c79d9ed2bc44985b1f01a0372a9e88 | |
parent | d203a0e0b4f2a1959fb3dc486a5ee6684b44ccb3 (diff) | |
download | rails-d7a2309fe39d3807c1c97de116b23d6bb2c08d79.tar.gz rails-d7a2309fe39d3807c1c97de116b23d6bb2c08d79.tar.bz2 rails-d7a2309fe39d3807c1c97de116b23d6bb2c08d79.zip |
Add group documentation
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 12 |
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 |