Let us consider an example with two models, where Doctor inherits from Person.
class Person include Mongoid::Document field :name embeds_many :locations, class_name: 'Location' end class Location include Mongoid::Document field :name embedded_in :person end class Street < Location field :number end
When a new person is instanced with many streets:
Person.new(name: 'Peter', locations: [{_type: 'Street', number: 5}])
Returns:
Mongoid::Errors::UnknownAttribute: message: Attempted to set a value for 'number' which is not allowed on the model Street. summary: Without including Mongoid::Attributes::Dynamic in your model and the attribute does not already exist in the attributes hash, attempting to call Street#number= for it is not allowed. This is also triggered by passing the attribute to any method that accepts an attributes hash, and is raised instead of getting a NoMethodError. resolution: You can include Mongoid::Attributes::Dynamic if you expect to be writing values for undefined fields often.
Since _type is a symbol it is completely ignored, it must be a String. What is the point of that? Shouldn't it be indifferent?
Problem is in lib/mongoid/factory.rb