lib/mongoid/factory.rb in mongoid-6.2.1 vs lib/mongoid/factory.rb in mongoid-6.3.0

- old
+ new

@@ -15,10 +15,11 @@ # @param [ Class ] klass The class to instantiate from if _type is not present. # @param [ Hash ] attributes The document attributes. # # @return [ Document ] The instantiated document. def build(klass, attributes = nil) - type = (attributes || {})[TYPE] + attributes ||= {} + type = attributes[TYPE] || attributes[TYPE.to_sym] if type && klass._types.include?(type) type.constantize.new(attributes) else klass.new(attributes) end