Don't save through associations twice (4-0-stable)

If the through record gets created in an after_create hook that is
defined before the association is defined (therefore after its
after_create hook) get saved twice. This ensures that the through
records are created only once, regardless of the order of the hooks.

Backports the fix for #3798 to 4.1. Slightly more conservative on the
callback order since it's a patch version, and required an additional
special case for HABTM
I know we're trying to reduce the use of checking symbols like this throughout the code base, as well as removing the `:has_man_belongs_to_many` symbol overall. I'm not sure what a better way to do this would be but I don't think this is the best way.