Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3093

Model#push behavior broken

    • Type: Icon: Task Task
    • Resolution: Done
    • 4.0.0 final
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      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' =>

      {field: values}

      }}}} 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.

            Assignee:
            durran Durran Jordan
            Reporter:
            mschulkind mschulkind
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: