Skip to content

Add documentation about setParameter with UID #14676

@jderusse

Description

@jderusse

The issue is, when using Raw DQL (or building the query) Doctrine does not have the context, and does not know what is an Ulid. When you call setParameter without providing the $type argument, Doctrine try to guess the type, and, sadly, the logic is very simplistic (see https://github.com/doctrine/orm/blob/2.7/lib/Doctrine/ORM/Query/ParameterTypeInferer.php).
by default, Doctrine think an ulid is a string and then, cast the value to string (while the value is stored as binary).

When using the Repository, you don't have such issue, because doctrine know the class and know the type of the field

Several solution for you.

  1. Help doctrine
->setParameter('ulid', $member->getUlid(), 'ulid')
  1. Convert value to a value compatible with the type inferred by doctine
->setParameter('ulid', $member->getUlid()->toBinary())
  1. Use Repository
$organisationMemberRepository->findOneBy(['user' => $user]);
$organisationMemberRepository->findOneBy(['user' => $user->getUlid()]);
$organisationMemberRepository->findOneByUser($user);

see symfony/symfony#39135 (comment) for full reference. Ping @warslett

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions