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

Model.first gives weird error

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

      Trying to upgrade to latest Mongoid.

      When I try and access elements in one of my models, I get the following error:

      > reload! Event.first
      NoMethodError: undefined method `each' for nil:NilClass
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager/base.rb:32:in `set_on_parent'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager/has_and_belongs_to_many.rb:22:in `block in preload'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager/has_and_belongs_to_many.rb:21:in `each'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager/has_and_belongs_to_many.rb:21:in `preload'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager/base.rb:17:in `run'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager.rb:42:in `block in preload'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager.rb:41:in `each'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager.rb:41:in `preload'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager.rb:33:in `eager_load'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager.rb:23:in `eager_load_one'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager.rb:17:in `block in with_eager_loading'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/contextual/mongo.rb:650:in `selecting'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/relations/eager.rb:14:in `with_eager_loading'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/contextual/mongo.rb:201:in `block (2 levels) in first'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/contextual/mongo.rb:537:in `with_sorting'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/contextual/mongo.rb:200:in `block in first'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/contextual/mongo.rb:449:in `try_cache'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/contextual/mongo.rb:199:in `first'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/contextual.rb:19:in `first'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/mongoid-4.0.0.alpha1/lib/mongoid/findable.rb:120:in `first'
      from (irb):5
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
      from /Users/danny/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
      from /Users/danny/Documents/workspace/ca/script/rails:6:in `require'
      from /Users/danny/Documents/workspace/ca/script/rails:6:in `<top (required)>'
      from -e:1:in `load'
      from -e:1:in `<main>'

      I don't get this error on any of my other models.

            Assignee:
            durran Durran Jordan
            Reporter:
            k2xl k2xl
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: