与mongoid的继承不一致

时间:2013-03-22 17:33:28

标签: ruby-on-rails inheritance mongoid

mongoid版本:mongoid(2.4.12) rails -v#=> Rails 3.1.10

class A
  include Mongoid::Document
  field :foo
  def self.inherited(klass)
  end
end
class B < A
  field :bar
end
class C < A
end

#C.new
# => #<C _id: 514c9505e3e50a856b000001, _type: "C", foo: nil, bar: nil>

1 个答案:

答案 0 :(得分:2)

您需要致电super,否则您将覆盖任何先前定义的inherited方法。所以你的功能应该是:

def self.inherited(klass)
  super
  #your code here
end

你破坏了mongoid inherited method