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

HABTM with foreign_key & primary_key set does not create reverse association

      Failing test case:

            animal = ForeignKeySpec::Animal.create!(a: 'bear')
            zoo = ForeignKeySpec::Zoo.create!(z: 'bz')
            animal.zoos << zoo
            animal.save!
      
            # This write should not be necessary, but without it the test fails.
            zoo.animals << animal
            zoo.save!
      
            expect(zoo.animals).to eq([animal])
            zoo = ForeignKeySpec::Zoo.find(zoo.id)
            expect(zoo.animals).to eq([animal])
      

      Due to this bug 4642 does not document specifying PK/FK with HABTM, since the combo appears to not work.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: