Skip to content

Entity form type fails when submiting an empty value for non-string identifier type on Postgres #23808

Closed
@maryo

Description

@maryo
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

This is almost the same issue as #14583 but I am afraid nobody would notice this old closed issue.

I am using entity type with required set to false and the entity's id is set to uuid type using ramsey/uuid-doctrine package with Postgres. It uses a different doctrine type than native guid - https://github.com/ramsey/uuid-doctrine/blob/master/src/UuidType.php named uuid. Doctrine maps it to guid Postgres type OFC but $metadata->getTypeOfField($identifier) returns uuid. So this condition is not satisfied
https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php#L75

A solution would be to check native types instead.

$databasePlatform = $qb->getEntityManager()->getConnection()->getDatabasePlatform();
$identifierMapping = $metadata->getFieldMapping($identifier);

if (Type::getType($metadata->getTypeOfField($identifier))->getSQLDeclaration($identifierMapping, $databasePlatform) === $databasePlatform->getGuidTypeDeclarationSQL($identifierMapping)) {
    // all types mapped to GUID
}

I can send a PR... but it's actually not very nice as well as filtering out those non-integer values in the condition above.

Why can't we filter out empty strings in all cases? Or at least skip array('') which covers entity type when both multiple and required is set to false (the values is an empty array in case when multiple is set true)? Or can we? Is there a case where empty string is not an empty choice?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions