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
Oh whoops carry on then 

> On Jun 14, 2014, at 12:06 PM, Sean Griffin <notifications@github.com> wrote:
> 
> In activerecord/lib/active_record/autosave_association.rb:
> 
> > @@ -359,6 +359,7 @@ def save_collection_association(reflection)
> >  
> >              raise ActiveRecord::Rollback unless saved
> >            end
> > +          @new_record_before_save = false unless reflection.macro == :has_and_belongs_to_many
> This is against 4-0-stable, not master.
> 
> —
> Reply to this email directly or view it on GitHub.