1

假设我有这些定义:

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 中,因此我无法修改源代码。我想覆盖 to 的默认行为,:dependent => :nullify:dependent => :destroy好像它是这样的:

class Post
  include Votable

  has_many :votes, :dependent => :destroy
end

我该怎么做呢?

4

0 回答 0