-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
also reported in Issue MONGOID-2877
This appears to be the right thing to do when storing these keys in the IdentityMap. At least it fixes the N+1 problem (which previously was not fixed).
Tested with variants of the following:
ruby Mongoid.identity_map_enabled = true Mongoid.unit_of_work do Band.includes(:albums).each do |band| puts "\n\nShould not see a QUERY log below this line" p band.albums.first.title # Does not hit the database again. Not true; it does! end end
and separately with polymorphism, where the classes were structured like this:
ruby class Band include Mongoid::Document has_many :albums, as: :commentable field :name end class Album include Mongoid::Document belongs_to :commentable, polymorphic: true field :title end