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

Setting array field with << doesn't persist

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.1
    • Affects Version/s: None
    • Component/s: None

      Tested with HEAD.

      class User
        ...
      
        field :foo, :type => Array, :default => []
      end
      
      >> u = User.last
      >> u.foo
      []
      >> u.foo << 1
      [
          [0] 1
      ]
      >> u.foo
      [
          [0] 1
      ]
      >> u.changes
      {}
      >> u.save(:validate => false)
      true
      >> u.reload
      >> u.foo
      []
      >> u.foo += [2]
      [
          [0] 2
      ]
      >> u.changes
      {
          "foo" => [
              [0] [],
              [1] [
                  [0] 2
              ]
          ]
      }
      >> u.save(:validate => false)
      true
      >> u.reload
      >> u.foo
      [
          [0] 2
      ]
      

      Couldn't find an issue on this. I would expect the first save to persist the change to :foo.

            Assignee:
            Unassigned Unassigned
            Reporter:
            wulffeld Martin Moen Wulffeld
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: