-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Using rails 4 and master branch and mongodb 2.2.3.
https://github.com/mongoid/mongoid/blob/master/lib/mongoid/persistable/pushable.rb#L49
is not quite right.
The way this works, I see at least 3 problems:
1. This totally breaks the atomic nature of such an operation. Can't you essentially do model.class.where(id: model.id).push(...)
2. You can't push an array onto an array with this. Should probably be using flatten(1) or other similar protection.
3. Pushes are just plain broken. Now that I run the tests, I see that the relevant test are also broken. The mongo command has the field name and $each swapped. It should be {{{'$push' => {'$each' =>
}}}} and right now it comes out as {{{'$push' => {field =>
{'$each' => values}}}}} so I get a literal {{
{'$each' => [value]}}} in my model's array, but this is only apparent after {{#reload}}ing the model.