【问题标题】:Inheritance inconsistency with mongoid继承与mongoid不一致
【发布时间】:2013-03-22 17:33:27
【问题描述】:

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>

【问题讨论】:

    标签: ruby-on-rails inheritance mongoid


    【解决方案1】:

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

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

    你正在破坏mongoid inherited method

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-26
      • 2012-10-30
      相关资源
      最近更新 更多