@@ -168,6 +168,35 @@ entity primary keys::
168
168
169
169
The UUID types and generators were introduced in Symfony 5.2.
170
170
171
+ When using built-in Doctrine repository methods (e.g. ``findOneBy() ``), Doctrine
172
+ knows how to convert these UUID types to build the SQL query
173
+ (e.g. ``->findOneBy(['user' => $user->getUuid()]) ``). However, when using DQL
174
+ queries or building the query yourself, you'll need to set ``uuid `` as the type
175
+ of the UUID parameters::
176
+
177
+ // src/Repository/ProductRepository.php
178
+
179
+ // ...
180
+ class ProductRepository extends ServiceEntityRepository
181
+ {
182
+ // ...
183
+
184
+ public function findUserProducts(User $user): array
185
+ {
186
+ $qb = $this->createQueryBuilder('p')
187
+ // ...
188
+ // add 'uuid' as the third argument to tell Doctrine that this is an UUID
189
+ ->setParameter('user', $user->getUuid(), 'uuid')
190
+
191
+ // alternatively, you can convert it to a value compatible with
192
+ // the type inferred by Doctrine
193
+ ->setParameter('user', $user->getUuid()->toBinary())
194
+ ;
195
+
196
+ // ...
197
+ }
198
+ }
199
+
171
200
ULIDs
172
201
-----
173
202
@@ -283,6 +312,35 @@ entity primary keys::
283
312
284
313
The ULID types and generator were introduced in Symfony 5.2.
285
314
315
+ When using built-in Doctrine repository methods (e.g. ``findOneBy() ``), Doctrine
316
+ knows how to convert these ULID types to build the SQL query
317
+ (e.g. ``->findOneBy(['user' => $user->getUlid()]) ``). However, when using DQL
318
+ queries or building the query yourself, you'll need to set ``ulid `` as the type
319
+ of the ULID parameters::
320
+
321
+ // src/Repository/ProductRepository.php
322
+
323
+ // ...
324
+ class ProductRepository extends ServiceEntityRepository
325
+ {
326
+ // ...
327
+
328
+ public function findUserProducts(User $user): array
329
+ {
330
+ $qb = $this->createQueryBuilder('p')
331
+ // ...
332
+ // add 'ulid' as the third argument to tell Doctrine that this is an ULID
333
+ ->setParameter('user', $user->getUlid(), 'ulid')
334
+
335
+ // alternatively, you can convert it to a value compatible with
336
+ // the type inferred by Doctrine
337
+ ->setParameter('user', $user->getUlid()->toBinary())
338
+ ;
339
+
340
+ // ...
341
+ }
342
+ }
343
+
286
344
.. _`unique identifiers` : https://en.wikipedia.org/wiki/UID
287
345
.. _`UUIDs` : https://en.wikipedia.org/wiki/Universally_unique_identifier
288
346
.. _`ULIDs` : https://github.com/ulid/spec
0 commit comments