Skip to content
Browse files

Update documentation on group method to indicate it takes an array

The group method also takes an array, however this isn't immediately
clear by reading the source since it delegates this method. If you
trace it back to the AREL building you can see that it does support
an array.

Shoutout to @betovelandia for pointing this out.
  • Loading branch information...
1 parent cc4c6d4 commit 6c821073f3eb0cb4acec8ad98fc54a25fd5fe6ce @estsauver estsauver committed Mar 17, 2014
Showing with 4 additions and 0 deletions.
  1. +4 −0 activerecord/lib/active_record/relation/query_methods.rb
View
4 activerecord/lib/active_record/relation/query_methods.rb
@@ -261,6 +261,10 @@ def select!(*fields) # :nodoc:
#
# User.group('name AS grouped_name, age')
# => [#<User id: 3, name: "Foo", age: 21, ...>, #<User id: 2, name: "Oscar", age: 21, ...>, #<User id: 5, name: "Foo", age: 23, ...>]
+ #
+ # Passing in an array of attributes to group by is also supported.
+ # User.select([:id, :first_name]).group(:id, :first_name).first(3)
+ # => [#<User id: 1, first_name: "Bill">, #<User id: 2, first_name: "Earl">, #<User id: 3, first_name: "Beto">]
def group(*args)
check_if_method_has_arguments!(:group, args)
spawn.group!(*args)

0 comments on commit 6c82107

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