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

Losing changed data when iterating via Cursor over Documents

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Object-Data getting lost

      When iterating with a cursor over a set of Mongoid Documents, the changes to those objects are lost outside the loop.
      Is this the expected behaviour?

      Please have a look at 'spec/computer_spec.rb' in https://github.com/QEDio/mongoid_error

      Run the spec with: rake

      What?

      class Computer
      include Mongoid::Document
      field :active, type: Boolean
      field :dirty, type: Boolean
      end

      This fails:

      computers = Computer.all

      1. computers = Computer.all.to_a fixes the problem

      computers.each do |c|
      c.active = true
      c.dirty = false
      end

      computers.each do |c|
      c.save
      end

      1. nothing gets updated

            Assignee:
            Unassigned Unassigned
            Reporter:
            jak4 jak4
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: