Method: ActiveRecord::QueryMethods#regroup

Defined in:
activerecord/lib/active_record/relation/query_methods.rb

#regroup(*args) ⇒ Object

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.



593
594
595
596
# 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