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

Broken embedded relation.

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

      So I have a model with an embeds many relation running in production. I recently got an invalid relation when trying to call say model.photos and the following error was thrown.

      NoMethodError: undefined method `[]' for nil:NilClass
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/factory.rb:38:in `from_db'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/builders/embedded/many.rb:25:in `block (2 levels) in build'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/builders/embedded/many.rb:23:in `each'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/builders/embedded/many.rb:23:in `block in build'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/builders/embedded/many.rb:22:in `tap'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/builders/embedded/many.rb:22:in `build'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/accessors.rb:43:in `create_relation'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/accessors.rb:26:in `build'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/accessors.rb:101:in `block (4 levels) in getter'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/threaded/lifecycle.rb:125:in `_loading'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/accessors.rb:100:in `block (3 levels) in getter'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/threaded/lifecycle.rb:84:in `_building'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/mongoid-2.4.9/lib/mongoid/relations/accessors.rb:99:in `block (2 levels) in getter'
      	from (irb):36
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
      	from /data/kyparn/shared/bundled_gems/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
      	from script/rails:6:in `require'
      

      I used model.unset('photos') to get rid of it so unfortunately I don't have any more to go on.
      Have you seen it before? And if so do you know what the cause is?

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

              Created:
              Updated:
              Resolved: