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

fix IdentityMap not storing relation keys properly

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • 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
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            mikerobe Mike Robertson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: