Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add group documentation

  • Loading branch information...
commit d7a2309fe39d3807c1c97de116b23d6bb2c08d79 1 parent d203a0e
@oscardelben oscardelben authored
Showing with 12 additions and 0 deletions.
  1. +12 −0 activerecord/lib/active_record/relation/query_methods.rb
View
12 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
Please sign in to comment.
Something went wrong with that request. Please try again.