3
我有以下模型設置。銷燬後不會被破壞關聯嗎?
class Space
has_many :locations, through: :location_spaces
has_many :location_spaces, dependent: :destroy, inverse_of: :space
end
class Location
has_many :spaces, through: :location_spaces
has_many :location_spaces, dependent: :destroy, inverse_of: :location
end
class LocationSpace
belongs_to :location, inverse_of: :location_spaces
belongs_to :space, inverse_of: :location_spaces
end
如果我通過修改空間模型的location_ids創建SpaceLocation,這也將觸發SpaceLocation的AFTER_CREATE回調。
但是,當您更新空間模型並將location_ids設置爲[]時,將刪除SpaceLocation。但是不會調用after_destroy回調。看着sql,破壞就成了。
爲什麼不調用after_destroy回調函數? 我試過每個「後」回調,包括after_touched,並沒有被稱爲。
這回答我的問題。 http://stackoverflow.com/questions/30629680/rails-isnt-running-destroy-callbacks-for-has-many-through-join-model – ShivamD