-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 5.1.4
-
Component/s: None
Mongoid raises an unexpected NoMethodError when trying to eager load through a nested relationship that is `nil`.
Concretely, given the models
class Blog include Mongoid::Document has_one :post end class Post include Mongoid::Document belongs_to :blog belongs_to :author end class Author include Mongoid::Document end
with seed data
Blog.create()
the following code
Blog.includes(:post => :author).to_a
raises the error
NoMethodError: undefined method `set_relation' for nil:NilClass
from /Users/martin/.rvm/gems/ruby-2.2.3/gems/mongoid-5.1.4/lib/mongoid/relations/eager/base.rb:148:in `set_relation'
Note that the non-nested version works correctly:
Blog.includes(:post).to_a
- duplicates
-
MONGOID-4313 Includes throws NoMethodError when document is nil
- Closed