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

mongoid 3.0.9 and update_all in embedded

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

      May refer to MONGOID-2403

      It seems to appear only when there is at least one document with field already "updated"

      class Book
        include Mongoid::Document
        attr_accessible :title
        embeds_many :pages
        field :title
      end
      class Page
        include Mongoid::Document
        attr_accessible :text
        embedded_in :book
        field :text
      end
      
      b = Book.create(:title => "Cloud Atlas")
      b.pages.create(text: "One")
      b.pages.create(text: "Two")
      b.pages.create(text: "Three")
      b.pages.update_all(:text => "ZERO")
      b.pages.all.map(&:text)
      b.pages.update_all(:text => "ZERO")
      

      in mongoid 3.0.6

      => #<Book _id: 507ab6341ffc6dde39000005, _type: nil, title: "Cloud Atlas">
      => #<Page _id: 507ab6341ffc6dde39000006, _type: nil, text: "One">
      => #<Page _id: 507ab6341ffc6dde39000007, _type: nil, text: "Two">
      => #<Page _id: 507ab6341ffc6dde39000008, _type: nil, text: "Three">
      => nil
      => ["ZERO", "ZERO", "ZERO"]
      => nil
      

      in mongoid 3.0.9

      => #<Book _id: 507ab7e41ffc6d7f3a000001, _type: nil, title: "Cloud Atlas">
      => #<Page _id: 507ab7e41ffc6d7f3a000002, _type: nil, text: "One">
      => #<Page _id: 507ab7e41ffc6d7f3a000003, _type: nil, text: "Two">
      => #<Page _id: 507ab7e41ffc6d7f3a000004, _type: nil, text: "Three">
      => nil
      => ["ZERO", "ZERO", "ZERO"]
      TypeError: can't convert nil into Hash
      from /Users/user/.rvm/gems/ruby-1.9.3-p125/gems/mongoid-3.0.9/lib/mongoid/contextual/memory.rb:289:in `merge!'
      

      Am I missing something?

      TIA

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

              Created:
              Updated:
              Resolved: