You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To replicate, consider the parent Plant model which has many child Site models:
classPlantfield:name,type: String,default: 'something'has_many:sites,dependent: :nullifyalize_to:sites,:nameendclassSitebelongs_to:plant,index: truealize_from:plant,:nameend# in the console -->p=Plant.create;s=Site.createplant: p;p.destroy!;s.reload=> <Site_id: 53fe26596731302734010000,plant_id: nil,plant_fields: {"name"=>"something"}>
# in the Site object, the :plant_id becomes nil, but the :plant_fields doesn't
From what I could understand from the code, _denormalize_destroy_to_#{relation} is defined as an after_destroy callback. But this method uses [self.#{relation}].flatten.compact to iterate over all the child objects, which will always return an empty array since the dependent: :nullify option on the parent will ensure that all child objects have their parent_id fields set to nil.
Changing the callback to a before_destroy callback fixes the above issue. But that doesn't seem like a good idea (IMO), since it would not work with dependent: :restrict option.
The text was updated successfully, but these errors were encountered:
To replicate, consider the parent
Plant
model which has many childSite
models:From what I could understand from the code,
_denormalize_destroy_to_#{relation}
is defined as anafter_destroy
callback. But this method uses[self.#{relation}].flatten.compact
to iterate over all the child objects, which will always return an empty array since thedependent: :nullify
option on the parent will ensure that all child objects have their parent_id fields set to nil.Changing the callback to a
before_destroy
callback fixes the above issue. But that doesn't seem like a good idea (IMO), since it would not work withdependent: :restrict
option.The text was updated successfully, but these errors were encountered: