magicgregz
magicgregz

Reputation: 7679

Inheritance inconsistency with mongoid

mongoid version: 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>

Upvotes: 0

Views: 106

Answers (1)

klochner
klochner

Reputation: 8125

You need to call super, otherwise you will overwrite any previously defined inherited methods. So your function should be:

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

You were clobbering the mongoid inherited method.

Upvotes: 2

Related Questions