Don't use AR's association_scope
association_scope is private in Rails 6 (since https://github.com/rails/rails/commit/0b4cfa2ba3e978386240e0e56a409616cc32fd02):
[...] NoMethodError: private method `association_scope' called for #<ActiveRecord::Associations::HasManyAssociation:0x00000000100e57f8> lib/core_extensions.rb:41:in `block in before_destroy' lib/core_extensions.rb:40:in `each' lib/core_extensions.rb:40:in `before_destroy' [...]
Fixes #28565 - Avoid association_scope method
ActiveRecord::Associations#association_scope has been changed to private
method in Rails 6. We replace it by explicitly creating the
AssociationScope we need.
Additionally, refactored EnsureNotUsedBy callback to be more efficient
by only loading the authorized associations' ids once instead of loading
all of the records again for every existing association still present.