doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.94k stars 2.52k forks source link

Unable to query by an array of Uuid #11712

Open fmonts opened 1 week ago

fmonts commented 1 week ago

It seems we are currently unable to query by an array of Uuids.

Neither

$leads = $this->em->getRepository(Lead::class)->findBy(['uuid' => $uuids]);

nor

$leads = $this->em->getRepository(Lead::class)->createQueryBuilder('l')
    ->where('l.uuid IN (:uuids)')
    ->setParameter('uuids', $uuids)
    ->getQuery()
    ->getResult();

work. Tested with Mysql 8.0.36. They are sent to db as strings, with the dashes included:

image

Tried with both strings and Uuid objects.

The findOneBy method works:

image

fmonts commented 1 week ago

Found a working solution, but it looks like a workaround:

$ids = array_map(fn($uuid) => Uuid::fromString($uuid)->toBinary(), $ids);

$leads = $this->em->getRepository(Lead::class)->createQueryBuilder('l')
    ->where('l.uuid IN (:ids)')
    ->setParameter('ids', $ids, ArrayParameterType::BINARY)