Fix redefine a has_and_belongs_to_many inside inherited class

After ad7b5efb55bcc2e0ccd3e7f22a81e984df8676d1, which changed how
has_an_belongs_to_many used to work, we start raising an error when
redefining the same has_an_belongs_to_many association. This commits fix
that regression.

[Fixes #14983]
Merge pull request #15358 from arthurnn/redefine_habtm_fix

Fix redefine a has_and_belongs_to_many inside inherited class