如何覆盖在ActiveRecord中继承的关联的依赖行为?

时间:2012-11-07 23:27:12

标签: ruby-on-rails activerecord

假设我有这些定义:

module Votable
  def self.included(klass)
    klass.class_eval do
      has_many :votes
    end
  end
end

class Post < ActiveRecord::Base
  include Votable
end

Votable模块包含在gem中,因此我无法修改源代码。我想将:dependent => :nullify的默认行为覆盖为:dependent => :destroy,就好像它是这样:

class Post
  include Votable

  has_many :votes, :dependent => :destroy
end

我将如何做到这一点?

0 个答案:

没有答案