HMT collection_singular_ids= deletion of join models is direct, no destroy callbacks are triggered

前端 未结 3 672
梦如初夏
梦如初夏 2021-02-06 02:24

Just ran into an issue with a has_many :through association and after/before-destroy callbacks not being triggered.

Say, I have users, groups, and an intermediate relati

3条回答
  •  忘了有多久
    2021-02-06 02:45

    adding dependent: :destroy to the has many relationship actually calls the before_destroy and after_destroy methods in the Membership class.

    class User < ActiveRecord::Base
      has_many :groups, through: :memberships, dependent: :destroy
    end
    

提交回复
热议问题