All Articles

Rails 7.1 adds regroup to ActiveRecord

Rails 7.1 adds regroup to ActiveRecord::Relation. regroup overrides the existing group condition with a new one. regroup is a short-hand for unscope(:old_group_fields).group(:new_group_fields)

Here is how it can be used., :owner)
# SELECT "projects".* FROM "projects" GROUP BY "projects"."title", "projects"."owner", :owner).regroup(:priority)
# SELECT "projects".* FROM "projects" GROUP BY "projects"."priority"

Here is the relevant pull request adding this change.