-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DoctrineBridge] Ulid is not converted to correct database type in queries #39135
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
Comments
AbstractUidType does not have this method override which I think it needs:
However I have added it in and I'm still not getting results back so I'll keep investigating. |
adding getBindingType breaks other things so had to take it off. This doesn't work either, still tried to use the string value as the parameter:
However this query executes correctly:
But this is not intuitive. I would expect to be able to just filter by the association or at least join the association and filter by the ulid object. |
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 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.
->setParameter('ulid', $member->getUlid(), 'ulid')
->setParameter('ulid', $member->getUlid()->toBinary())
$organisationMemberRepository->findOneBy(['user' => $user]);
$organisationMemberRepository->findOneBy(['user' => $user->getUlid()]);
$organisationMemberRepository->findOneByUser($user); |
thanks @jderusse I've adopted Some times it is necessary to use the querybuilder instead of using a repository. For example when using any tool that needs to alter the query before running it such as pagination libraries or tools that provide generic functionality for interacting with data such as admin bundles that might need to apply sorts and filters before the query is executed etc. In the long term it would be great if Doctrine could support some way of registering parameter type mappings for objects. I will create a feature request if I get a chance |
In my case, for many to many I used this solution ...
// for the ManyToMany
$ctoBinary = array_map(
fn($category) => $category->getId()->toBinary(),
$data->categories
);
$qb = $qb
->andWhere('c.id IN (:categories)')
->setParameter('categories', $ctoBinary,);
.... |
well, Doctrine DBAL has a |
Maybe something can be done on doctrine's |
Okay I just discovered that this is a major problem with no workarounds for eager loads, when using |
Issue is open there on doctrine doctrine/dbal#4660 |
Dear Community, I'm reaching out regarding an ongoing issue on GitHub concerning eager loading with Symfony's ULID. After thorough investigation and attempts at resolution, it seems that no definitive solution has been found thus far. I'm encountering the same problem with eager loading and ULID in Symfony, and I see that others have faced similar challenges. I would greatly appreciate it if anyone who has successfully resolved this issue could share their insights or provide guidance on how to tackle it. Any assistance in formulating a solution would be immensely beneficial.Dear Community, |
This issue is closed, please open a new one for any follow up. |
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected: 5.2.0-RC2 (PHP 7.4.11 MySQL 8.0.22)
Description
I think this was an issue on RC1 as well but I only discovered it last night. When I run doctrine queries the Ulid field of parameters in the query are not being converted into the format of the corresponding column in the database meaning you don't get any matches.
The tldr; is that it is just passing the ulid in as a string when running queries and not converting it to the format in which it is stored in the database binary.
I have the following entities:
and
And this migration:
In organisation_member I have this data:
In user I have this data:
When I run this query
I get back 0 results even though the data is there. When I take a look in MySQL general_log I can see the following query was executed:
It is just passing the ulid in as a string and not converting it to the format in which it is stored in the database (binary)
If I manually run the query but substitute the parameter that doctrine used for the correctly encoded parameter I get one result back as expected:
How to reproduce
Detailed steps above but the short version:
SET GLOBAL general_log = 'ON'; SET GLOBAL log_output = 'TABLE';
Possible Solution
We need to bind uuid types by converting the value to binary and then using the binary parameter type.
Additional context
#39113 was merged for RC2 to change the way ulid is stored in the mysql from a uuid string to uuid binary however I also observed this same issue in RC1 where the data was stored in the db as uuid string but the query parameter was encoded as ulid.
The text was updated successfully, but these errors were encountered: