lib/mongomodel/concerns/attributes.rb in mongomodel-0.2.3 vs lib/mongomodel/concerns/attributes.rb in mongomodel-0.2.4

- old
+ new

@@ -3,11 +3,11 @@ module MongoModel module Attributes extend ActiveSupport::Concern def initialize(attrs={}) - self.attributes = attrs + self.attributes = (attrs || {}) yield self if block_given? end def attributes @attributes ||= Attributes::Store.new(self) @@ -49,17 +49,21 @@ attributes.values.select { |attr| attr.is_a?(Collection) }.each do |collection| docs.concat collection.embedded_documents end + attributes.values.select { |attr| attr.is_a?(Map) && attr.to <= EmbeddedDocument }.each do |map| + docs.concat map.values + end + docs end module ClassMethods def from_mongo(hash) if hash doc = class_for_type(hash['_type']).new - doc.attributes.from_mongo!(hash) + doc.attributes.load!(hash) doc end end private