lib/mongo_mapper/plugins/modifiers.rb in mongo_mapper-0.7.5 vs lib/mongo_mapper/plugins/modifiers.rb in mongo_mapper-0.7.6

- old
+ new

@@ -12,22 +12,26 @@ keys.keys.each_with_index { |k, i| to_decrement[k] = -values[i].abs } collection.update(criteria, {'$inc' => to_decrement}, :multi => true) end def set(*args) - modifier_update('$set', args) + criteria, updates = criteria_and_keys_from_args(args) + updates.each do |key, value| + updates[key] = keys[key].set(value) if key?(key) + end + collection.update(criteria, {'$set' => updates}, :multi => true) end def unset(*args) if args[0].is_a?(Hash) criteria, keys = args.shift, args else keys, ids = args.partition { |arg| arg.is_a?(Symbol) } criteria = {:id => ids} end - criteria = to_criteria(criteria) + criteria = query(criteria).criteria.to_hash modifiers = keys.inject({}) { |hash, key| hash[key] = 1; hash } collection.update(criteria, {'$unset' => modifiers}, :multi => true) end def push(*args) @@ -55,17 +59,17 @@ modifier_update('$pop', args) end private def modifier_update(modifier, args) - criteria, keys = criteria_and_keys_from_args(args) - collection.update(criteria, {modifier => keys}, :multi => true) + criteria, updates = criteria_and_keys_from_args(args) + collection.update(criteria, {modifier => updates}, :multi => true) end def criteria_and_keys_from_args(args) keys = args.pop criteria = args[0].is_a?(Hash) ? args[0] : {:id => args} - [to_criteria(criteria), keys] + [query(criteria).criteria.to_hash, keys] end end module InstanceMethods def unset(*keys) \ No newline at end of file