Custom type id settings not applied in ManyToOne #6556

Open
opened 2026-01-22 15:34:57 +01:00 by admin · 0 comments
Owner

Originally created by @garak on GitHub (Oct 16, 2020).

I'm using a custom type as id (in my case, it's a ShortidType)
Such type accept a length option in its defintion.
If I pass such option, my field is generated accordingly. Unfortunately, the same doesn't apply to a ManyToOne definition, where option is ignored.
The following example is about defining a Game entity with many Player entities associated:

<?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 http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
    <entity name="Entity\Game">
        <id name="id" type="shortid" length="9"/>
        <one-to-many field="players" target-entity="Entity\Player" mapped-by="game"/>
    </entity>
</doctrine-mapping>
<?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 http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
   <entity name="Entity\Player">
       <id name="id" type="shortid" length="9"/>
       <many-to-one field="game" target-entity="Entity\Game" inversed-by="players">
           <join-column nullable="true"/>
       </many-to-one>
   </entity>
</doctrine-mapping>

When I build the schema for such mapping, the id fields for both Game and Player are correctly generated with a length of 9.
Instead, the game_id field generated in the player table is generated with the default length of 7.

Originally created by @garak on GitHub (Oct 16, 2020). I'm using a custom type as id (in my case, it's a [ShortidType](https://github.com/PUGX/shortid-doctrine)) Such type accept a `length` [option](https://github.com/PUGX/shortid-doctrine/blob/master/src/ShortidType.php#L21) in its defintion. If I pass such option, my field is generated accordingly. Unfortunately, the same doesn't apply to a ManyToOne definition, where option is ignored. The following example is about defining a Game entity with many Player entities associated: ```xml <?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 http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > <entity name="Entity\Game"> <id name="id" type="shortid" length="9"/> <one-to-many field="players" target-entity="Entity\Player" mapped-by="game"/> </entity> </doctrine-mapping> ``` ```xml <?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 http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > <entity name="Entity\Player"> <id name="id" type="shortid" length="9"/> <many-to-one field="game" target-entity="Entity\Game" inversed-by="players"> <join-column nullable="true"/> </many-to-one> </entity> </doctrine-mapping> ``` When I build the schema for such mapping, the `id` fields for both Game and Player are correctly generated with a `length` of 9. Instead, the `game_id` field generated in the `player` table is generated with the default `length` of 7.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6556