Skip to content

Add documentation about setParameter with UID #14676

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

Closed
jderusse opened this issue Dec 8, 2020 · 0 comments
Closed

Add documentation about setParameter with UID #14676

jderusse opened this issue Dec 8, 2020 · 0 comments
Milestone

Comments

@jderusse
Copy link
Member

jderusse commented Dec 8, 2020

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

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

No branches or pull requests

2 participants