Mongodb-odm: Document class is unlisted in the discriminator map - using no discriminator map

Created on 10 Apr 2019  路  6Comments  路  Source: doctrine/mongodb-odm

Bug Report

| Q | A
|------------ | ------
| BC Break | yes
| Version | 2.0.0-beta2

Summary

Document class "Domain\XYZ\Document" is unlisted in the discriminator map although I am using no discriminator map.

Possibly related to this: https://github.com/doctrine/mongodb-odm/issues/867

Current behavior

Let's assume this code:

/**
 * @ODM\Document()
 * @ODM\InheritanceType("SINGLE_COLLECTION")
 * @ODM\DiscriminatorField("class")
 */
class DocumentA {
    /**
     * @ODM\ReferenceOne(targetDocument="DocumentA")
     * @ODM\Index
     * @var Document|null
     */
    public $parentDocument;
}

/**
 * @ODM\Document()
 */
class DocumentB extends DocumentA {
}

$docB = new DocumentB;
$docB->parentDocument = $docA;

Now I get the Document class "DocumentA" is unlisted in the discriminator map exception on a flush.

The interesting fact is that when I create the $docA in the same script as the $docB everything works.

However when I load it from the database prior setting it to the property, I get the exception.

Bug Has PR

All 6 comments

Could you by any chance reproduce this in a test case? You can find a whole bunch of such test cases in https://github.com/doctrine/mongodb-odm/tree/master/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket. Thanks!

Will give it a shot.

Done. I hope the clearing loaded metadata like that is okay. It simulates my problem where request that doesn't work with document A but works with document B fails.

Until the bug is fixed, I forked the ODM and just plainly disabled the exception whatsoever to enable me to work on my project.

Fix has been merged to 1.3 and master. Thanks for reporting, and more so for the failing test case!

The exception went away, but a new problem appeared. See: #2024

Was this page helpful?
0 / 5 - 0 ratings