doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.93k stars 2.51k forks source link

Support enum-type for id field in XML mapping #11280

Open tmihalicka opened 7 months ago

tmihalicka commented 7 months ago

Bug Report

Q A
BC Break no
Version 2.18.1 / 3.0.1

Summary

Missing support for enum-type in XML mapping

yaml, annotations and attibutes support enumType for Id field mapping but this is missing from xml mapping, and mising this option in xsd schema too.

Current behavior

It's not possible to add enum-type to XML mapping for Id field

How to reproduce

Try add enum-type to id field in xml mapping for example:

<?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="Offer" table="offer">
        <id name="id" type="OfferId" column="id"/>
        <id name="type" type="string" enum-type="OfferType" column="type"/>
    </entity>
</doctrine-mapping>

Expected behavior

Possible declare enum-type for Id field in xml mapping.

kimhemsoe commented 7 months ago

Works for me with FQCN. Btw may i ask why you need to specify? ORM can read the type from entity.

tmihalicka commented 7 months ago

And it's works for you in XML becuase XSD schema is missing enum-type for Id field?

tmihalicka commented 7 months ago

For example this is annotation and attribute example

    /**
     * @ORM\Id()
     * @ORM\Column(type="string", enumType=Unit::class)
     */
    #[Id]
    #[Column(type: 'string', enumType: Unit::class)]
    public Unit $unit;

But for XML there is no way how to define enum-type for Id field

kimhemsoe commented 7 months ago

Sorry miss read. Just checked xml driver and it seems to have support, but the xsd never got updated.

What you can now as a workaround is either disable xsd validation until someone makes a PR or remove the enum-type from the xml and let ORM read the type via reflection.

In your example you can remove "enumType=Unit::class" and "enumType: Unit::class" and it will work.

tmihalicka commented 7 months ago

Sure i will open PR with fixed XSD mapping :)

SmasherHell commented 12 hours ago

@tmihalicka is there any news on that issue ? The xsd does not seems updated to support enum-type attribute