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

Identity map breaks inverse relations

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

      Related to issue MONGOID-3009 - perhaps a generalized problem. has_many / belongs_to does not properly update the inverse relation when the identity map is enabled.

      class Image
          include Mongoid::Document
          belongs_to :page
      end
      
      class Page
          include Mongoid::Document
          has_many :images
      end
      
      describe Mongoid do
          def check_inverse_relation
              i = Image.new
              i.save!
              p = Page.new
              i.page = p
              p.save!
              i.page.should_not be nil
              p.images.length.should == 1  # this fails with identity map enabled
          end
      
          it "works with identity map off" do
              Mongoid.identity_map_enabled = false
              check_inverse_relation
          end
      
          it "fails with idenity map on" do
              Mongoid.identity_map_enabled = true
              check_inverse_relation
          end
      end
      

      (Please tell me I'm doing it wrong because I'd love the problem to be in my code not mongoid.)

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

              Created:
              Updated:
              Resolved: