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

add_to_set on embedded doc field errors

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

      a couple of issues, Hash#nested null pointer when the first return in the iternation is nil and AddtoSet#persist doesn't handle nil. This is in 3.1.4. I haven't tested on 4.x master, the code seems to have been re-factored quite a bit there anyway.

      here's a reduction

      class Foo
      include Mongoid::Document
      embeds_one :bar, autobuild: true

      class Bar
      include Mongoid::Document
      field :beers, type: Array, default: []
      end
      end

      Foo.create.add_to_set('bar.beers', %w(stone pabst))

      here's the exception

      NoMethodError: undefined method `[]' for nil:NilClass
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/extensions/hash.rb:104:in `block in nested'
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/extensions/hash.rb:103:in `each'
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/extensions/hash.rb:103:in `nested'
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/attributes.rb:91:in `read_attribute'
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/persistence/atomic/add_to_set.rb:21:in `block in persist'
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/persistence/atomic/operation.rb:91:in `prepare'
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/persistence/atomic/add_to_set.rb:20:in `persist'
      from /Users/paul/.rvm/gems/ruby-1.9.3-p392@myapp/gems/mongoid-3.1.4/lib/mongoid/persistence/atomic.rb:41:in `add_to_set'

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

              Created:
              Updated:
              Resolved: