Ruby on rails 销毁后未调用关联销毁?

Ruby on rails 销毁后未调用关联销毁?,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我有以下型号的设置 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: :des

我有以下型号的设置

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_id来创建SpaceLocation,这也会触发SpaceLocation的AFTER_create回调

但是,当您更新空间模型并将位置_id设置为[]时,将删除该空间位置。但是,不调用after_destroy回调。看看sql,破坏就发生了

为什么不调用after_destroy回调? 我尝试了每一次“之后”回调,包括触摸之后,但没有调用任何内容。

来自:

还有一种
clear
方法与
delete\u all
方法相同,只是它返回关联,而不是已删除的记录

从:

删除与
条件
匹配的记录,而不首先实例化记录,因此不调用
销毁
方法,也不调用回调

这回答了我的问题。