instance method regroup

Ruby on Rails 8.1.2

Since v7.1.6

Available in: v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

regroup(*args)

Allows you to change a previously set group statement.

Post.group(:title, :body)
# SELECT `posts`.`*` FROM `posts` GROUP BY `posts`.`title`, `posts`.`body`

Post.group(:title, :body).regroup(:title)
# SELECT `posts`.`*` FROM `posts` GROUP BY `posts`.`title`

This is short-hand for unscope(:group).group(fields). Note that we’re unscoping the entire group statement.

Parameters

args rest
Source
# File activerecord/lib/active_record/relation/query_methods.rb, line 593
    def regroup(*args)
      check_if_method_has_arguments!(__callee__, args)
      spawn.regroup!(*args)
    end

Defined in activerecord/lib/active_record/relation/query_methods.rb line 593 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::QueryMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close