lib/mongoid/factory.rb in mongoid-2.0.2 vs lib/mongoid/factory.rb in mongoid-2.1.0

- old
+ new

@@ -14,10 +14,10 @@ # @param [ Hash ] attributes The document attributes. # # @return [ Document ] The instantiated document. def build(klass, attributes = {}) type = (attributes || {})["_type"] - type.blank? ? klass.new(attributes) : type.constantize.new(attributes) + (type && klass._types.include?(type)) ? type.constantize.new(attributes) : klass.new(attributes) end # Builds a new +Document+ from the supplied attributes loaded from the # database. #