diff options
author | Earl St Sauver <estsauver@gmail.com> | 2014-03-17 11:28:57 -0700 |
---|---|---|
committer | Earl St Sauver <estsauver@gmail.com> | 2014-03-17 11:28:57 -0700 |
commit | 6c821073f3eb0cb4acec8ad98fc54a25fd5fe6ce (patch) | |
tree | 7973ea0d61826f9d4db9c5d806d0424e9574a44e | |
parent | cc4c6d405df8d4339112b44670dcce1b52e93f42 (diff) | |
download | rails-6c821073f3eb0cb4acec8ad98fc54a25fd5fe6ce.tar.gz rails-6c821073f3eb0cb4acec8ad98fc54a25fd5fe6ce.tar.bz2 rails-6c821073f3eb0cb4acec8ad98fc54a25fd5fe6ce.zip |
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.
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 3a5b3116eb..eff10d3575 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -261,6 +261,10 @@ module ActiveRecord # # 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) |