将 :before_save 添加到 AR 模型是否会覆盖已通过自定义扩展添加到 AR 的模型?

Does adding a :before_save to an AR model override one already added through a custom extension to AR?

我们使用一组自定义 'magic' 列,我们会在每个 AR 模型中检查这些列。如果找到任何内容,则在调用 save 或 save! 之前适当填充它们。这是使用以下代码作为初始值设定项完成的:

module HLLAuditStamps
  extend ActiveSupport::Concern

  included do
    before_save :set_audit_attributes
  end

  private

  def set_audit_attributes
    . . .
  end
end

class ActiveRecord::Base
  include HLLAuditStamps
end

我的问题是:如果我们向其中一个模型添加 before_save 回调,这段代码会发生什么情况?两者都会被处决吗?模型回调是否覆盖初始化程序中提供的默认回调?

澄清一下,上面添加的默认回调和添加到特定模型的任何自定义 before_save 回调都将执行。 . .我相信 ActiveRecord::Callbacks 文档中 "Inheritable callback queues" 下描述的相同规则将适用。像 before_save "add behavior into a callback queue that is kept intact down through an inheritance hierarchy." 这样的回调宏 – Jordan