views:

18

answers:

1

that is, if app/models/animal.rb has

class Animal
  include Mongoid::Document
  field :name, :type => String
  field :birthday, :type => Time
end

and then in app/models/cat.rb

class Cat < Animal
  include Mongoid::Document
  field :nail_length, :type => Float
end

then do you need to set some kind of "type" in Animal to remember it is a Cat, or is it automatic?

+1  A: 

An additional attribute _type is stored in order to make sure when loaded from the database the correct document is returned. This also holds true for the embedded documents Circle, Rectangle, and Shape. Fields and validations are inherited down the hierachy, but not up. A subclass will contain all of its parent's fields and validations, but not vise-versa.

http://mongoid.org/docs/inheritance/

Matt Briggs