Rails 5.2关联回调未在before_add或before_remove上触发 [英] Rails 5.2 Association callbacks not firing on before_add or before_remove
本文介绍了Rails 5.2关联回调未在before_add或before_remove上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有HABTM的活动模型:
I have an Activity model with HABTM:
has_and_belongs_to_many :contacts,
-> { distinct },
before_add: :contact_calculate_score,
before_remove: :contact_calculate_score
def contact_calculate_score(contact)
binding.pry
contact.calculate_score
end
对此有很多问题,例如这一个.
There are quite a few questions on this, for example this one.
我尝试使用'<<'将活动插入联系人中,但仍然不会触发回调.为什么不叫它?
I have tried using '<<' to insert activities into contacts, but still the callback does not fire. Why is it not being called?
查看全文