Permalink
Browse files

Add group documentation

  • Loading branch information...
oscardelben committed Jul 6, 2012
1 parent d203a0e commit d7a2309fe39d3807c1c97de116b23d6bb2c08d79
Showing with 12 additions and 0 deletions.
  1. +12 −0 activerecord/lib/active_record/relation/query_methods.rb
@@ -142,6 +142,18 @@ def select!(value)
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

0 comments on commit d7a2309

Please sign in to comment.