lib/mongoo/modifiers.rb in mongoo-0.5.5 vs lib/mongoo/modifiers.rb in mongoo-0.5.6

- old
+ new

@@ -25,11 +25,15 @@ end def cast_value(v) if v.is_a?(Mongoo::Embedded::Base) return v.to_hash - end; v + elsif v.is_a?(Array) + v.collect { |e| e.is_a?(Mongoo::Embedded::Base) ? e.to_hash : e } + else + v + end end def inc(k, v=1) v = sanitize_value(k,v) @queue["$inc"] ||= {} @@ -104,18 +108,19 @@ update_opts = @opts.delete(:update_opts) || {} ret = @doc.collection.update(update_query, @queue, update_opts) if !ret.is_a?(Hash) || (ret["err"] == nil && ret["n"] == 1) @queue.each do |op, op_queue| op_queue.each do |k, v| + duped_v = Marshal.load(Marshal.dump(v)) case op when "$inc" then new_val = @doc.persisted_mongohash.dot_get(k).to_i + v @doc.mongohash.dot_set( k, new_val ) @doc.persisted_mongohash.dot_set( k, new_val ) when "$set" then @doc.mongohash.dot_set( k, v ) - @doc.persisted_mongohash.dot_set( k, v ) + @doc.persisted_mongohash.dot_set( k, duped_v ) when "$unset" then @doc.mongohash.dot_delete( k ) @doc.persisted_mongohash.dot_delete( k ) when "$push" then unless @doc.persisted_mongohash.dot_get(k) @@ -123,31 +128,31 @@ end unless @doc.mongohash.dot_get(k) @doc.mongohash.dot_set(k, []) end - @doc.persisted_mongohash.dot_get(k) << v + @doc.persisted_mongohash.dot_get(k) << duped_v @doc.mongohash.dot_get(k) << v when "$pushAll" then unless @doc.persisted_mongohash.dot_get(k) @doc.persisted_mongohash.dot_set(k, []) end unless @doc.mongohash.dot_get(k) @doc.mongohash.dot_set(k, []) end - @doc.persisted_mongohash.dot_get(k).concat(v) + @doc.persisted_mongohash.dot_get(k).concat(duped_v) @doc.mongohash.dot_get(k).concat(v) when "$addToSet" then unless @doc.persisted_mongohash.dot_get(k) @doc.persisted_mongohash.dot_set(k, []) end unless @doc.mongohash.dot_get(k) @doc.mongohash.dot_set(k, []) end unless @doc.persisted_mongohash.dot_get(k).include?(v) - @doc.persisted_mongohash.dot_get(k) << v + @doc.persisted_mongohash.dot_get(k) << duped_v end unless @doc.mongohash.dot_get(k).include?(v) @doc.mongohash.dot_get(k) << v end when "$pop" then \ No newline at end of file