For a very long time in Rails,
it was not possible to combine delete statements with GROUP_BY and HAVING queries.
It does seem like something that should have been supported out of the box,
but unfortunately was overlooked — until now!
Using GROUP_BY or HAVING in a delete statement was ignored.
Let’s look at an example.
a user has multiple votes,
we’re trying to count users who have less than three votes.
If we do update_all with group and having clause ActiveRecord would ignore it.
However, when we try to delete these users, we end up with an error.