group(*args)
Instance Public methods
Allows to specify a group attribute:
User.group(:name) => SELECT "users".* FROM "users" GROUP BY name
Returns an array with distinct 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", ...>] 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, ...>]
Please login to continue.