Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow FQCN in value attribute of discriminator-mapping field #11449

Open
MatteoFeltrin opened this issue May 13, 2024 · 0 comments
Open

Allow FQCN in value attribute of discriminator-mapping field #11449

MatteoFeltrin opened this issue May 13, 2024 · 0 comments

Comments

@MatteoFeltrin
Copy link

Bug Report

We are storing to database FQCN to later use them to know which class the Entity has to be casted to through a Discriminator map.
We found out the problem updating to newer version of Doctrine which changed the default value of $isXsdValidationEnabled to true.
Actually, the attribute value of discriminator-mapping is set as XS:NMTOKEN in the XSD schema

image

Our XML Configuration of the entity:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="App\Core\EntityVersioning\Domain\Model\EntityVersion" table="entity_version" inheritance-type="SINGLE_TABLE">
    <discriminator-column name="entityType" type="string"/>
    <discriminator-map>
      <discriminator-mapping value="App\Core\Part\Domain\Model\Part" class="App\Core\Part\Domain\Model\PartVersion" />
      <discriminator-mapping value="App\Core\Card\Domain\Model\Card" class="App\Core\Card\Domain\Model\CardVersion" />
    </discriminator-map>
    <field name="version" type="string" nullable="false"/>
    <id name="entityId" type="string"/>
    <id name="entityType" association-key="true"/>
  </entity>
</doctrine-mapping>

Found out this related issue:
#10627

Q A
BC Break no
Version 3.1.x

Summary

Allow FQCN in value attribute of discriminator-mapping (or just loosen the type validation)

Current behavior

An exception is thrown when the XML is validated against the XSD configuration.

        Doctrine\ORM\Mapping\MappingException: libxml error: Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}discriminator-mapping', attribute 'value': 'App\Core\Part\Domain\Model\Part' is not a valid value of the atomic type 'xs:NMTOKEN'.
        in /src/Common/Infrastructure/Persistence/Doctrine/XmlMetadata/App.Core.EntityVersioning.Domain.Model.EntityVersion.dcm.xml at line 6
        libxml error: Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}discriminator-mapping', attribute 'value': 'App\Core\Card\Domain\Model\Card' is not a valid value of the atomic type 'xs:NMTOKEN'.
        in /src/Common/Infrastructure/Persistence/Doctrine/XmlMetadata/App.Core.EntityVersioning.Domain.Model.EntityVersion.dcm.xml at line 7

How to reproduce

Just write a backslash, or FQCN, inside the attribute "value" of a discriminator mapping field and let it be validated against XSD schema

Expected behavior

No exception to be thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant