Skip to content
  • Dmytro Savochkin's avatar
    781ecc22
    Ensure `reload` sets correct owner for each association · 781ecc22
    Dmytro Savochkin authored
    Fix #46363.
    
    Currently calling `reload` re-calculates the association cache based
    on the object freshly loaded from the database. The fresh object gets
    assigned as `owner` for each association in the association cache.
    That object however is not the same as `self` (even though they
    both point to the same record). Under some specific circumstances
    (using `has_one/has_many through` associations and transactions with
    `after_commit` callbacks) this might lead to losing the effects of
    assignments done inside the callback.
    
    This commit fixes it by making `reload` point to `self` as `owner`
    for each association in the association cache.
    781ecc22
    Ensure `reload` sets correct owner for each association
    Dmytro Savochkin authored
    Fix #46363.
    
    Currently calling `reload` re-calculates the association cache based
    on the object freshly loaded from the database. The fresh object gets
    assigned as `owner` for each association in the association cache.
    That object however is not the same as `self` (even though they
    both point to the same record). Under some specific circumstances
    (using `has_one/has_many through` associations and transactions with
    `after_commit` callbacks) this might lead to losing the effects of
    assignments done inside the callback.
    
    This commit fixes it by making `reload` point to `self` as `owner`
    for each association in the association cache.
Loading