-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
It seems like mongoid is storing incomplete objects inside the identity map, check examples below:
Without identity_map_enabled
$ rails console
Loading development environment (Rails 3.1.1)
ruby-1.9.2-p290 :001 > s = Show.without(:episodes).first
=> # < Show _id: 4ec30e7722bbec0007000000, ...>
ruby-1.9.2-p290 :002 > s.episodes.size
=> 0
ruby-1.9.2-p290 :003 > s = Show.find('4ec30e7722bbec0007000000')
=> # < Show _id: 4ec30e7722bbec0007000000, ...>
ruby-1.9.2-p290 :004 > s.episodes.size
=> 33
With identity_map_enabled: true
$ rails console
Loading development environment (Rails 3.1.1)
ruby-1.9.2-p290 :003 > s = Show.without(:episodes).first
=> # < Show _id: 4ec30e7722bbec0007000000, ...>
ruby-1.9.2-p290 :004 > s.episodes.size
=> 0
ruby-1.9.2-p290 :005 > s = Show.find('4ec30e7722bbec0007000000')
=> # < Show _id: 4ec30e7722bbec0007000000, ...>
ruby-1.9.2-p290 :006 > s.episodes.size
=> 0
I'm not sure about what would be the correct behavior. IMO mongoid should either make a new query fetching the empty fields or never include incomplete objects inside the identity map.