Flowdock
method

group

Importance_1
Ruby on Rails latest stable (v4.1.8) - 0 notes - Class: ActiveRecord::QueryMethods
group(*args) public

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, ...>]
Show source
Register or log in to add new notes.