Skip to content
  • Larry Reid's avatar
    332e7601
    Fix circular `autosave: true` · 332e7601
    Larry Reid authored
    Use a variable local to the `save_collection_association` method in
    `activerecord/lib/active_record/autosave_association.rb`, instead of an
    instance variable.
    
    Prior to this PR, when there was a circular series of `autosave: true`
    associations, the callback for a `has_many` association was run while
    another instance of the same callback on the same association hadn't
    finished running. When control returned to the first instance of the
    callback, the instance variable had changed, and subsequent associated
    records weren't saved correctly. Specifically, the ID field for the
    `belongs_to` corresponding to the `has_many` was `nil`.
    
    Remove unnecessary test and comments.
    
    Fixes #28080.
    332e7601
    Fix circular `autosave: true`
    Larry Reid authored
    Use a variable local to the `save_collection_association` method in
    `activerecord/lib/active_record/autosave_association.rb`, instead of an
    instance variable.
    
    Prior to this PR, when there was a circular series of `autosave: true`
    associations, the callback for a `has_many` association was run while
    another instance of the same callback on the same association hadn't
    finished running. When control returned to the first instance of the
    callback, the instance variable had changed, and subsequent associated
    records weren't saved correctly. Specifically, the ID field for the
    `belongs_to` corresponding to the `has_many` was `nil`.
    
    Remove unnecessary test and comments.
    
    Fixes #28080.
Loading