• A
    Only nullify persisted has_one target associations · 19b168e6
    Agis- 提交于
    Since after 87d1aba3 `dependent: :destroy` callbacks on has_one
    assocations run *after* destroy, it is possible that a nullification is
    attempted on an already destroyed target:
    
        class Car < ActiveRecord::Base
          has_one :engine, dependent: :nullify
        end
    
        class Engine < ActiveRecord::Base
          belongs_to :car, dependent: :destroy
        end
    
        > car = Car.create!
        > engine = Engine.create!(car: car)
        > engine.destroy! # => ActiveRecord::ActiveRecordError: cannot update a
        >   destroyed record
    
    In the above case, `engine.destroy!` deletes `engine` and *then* triggers the
    deletion of `car`, which in turn triggers a nullification of `engine.car_id`.
    However, `engine` is already destroyed at that point.
    
    Fixes #21223.
    19b168e6
has_one_association.rb 3.6 KB