Skip to content
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

Cannot bind uuid_binary type to Doctrine's QueryBuilder #266

Open
subdee opened this issue May 20, 2024 · 4 comments
Open

Cannot bind uuid_binary type to Doctrine's QueryBuilder #266

subdee opened this issue May 20, 2024 · 4 comments
Labels

Comments

@subdee
Copy link

subdee commented May 20, 2024

Description

A BINARY type does not seem to be supported in doctrine now.

If I bind the binary representation of the ID in a param I get an error from the ORM.

This is the parameter:

->setParameter(':column', $entity->getId()->getBytes())

and the error is Unhandled match case 16 which is coming from this method in doctrine/orm and is simply missing a match for ParameterType::BINARY.

Adding the type explicitly results in the same error.

doctrine/orm: 3.1.3
doctrine/dbal: 3.8.4
ramsey/uuid-doctrine: 2.0.0

Edit: The above worked fine with
doctrine/orm: 2.19.4
doctrine/dbal: 3.8.3
ramsey/uuid-doctrine: 1.8.2
where the above method does not exist

Steps to reproduce

Use the QueryBuilder to retrieve data based on a foreign key with uuid_binary type

Expected behavior

To get the right data back from the database

Screenshots or output

Error is Unhandled match case 16

Environment details

doctrine/orm: 3.1.3
doctrine/dbal: 3.8.4
ramsey/uuid-doctrine: 2.0.0

Additional context

@subdee subdee added the bug label May 20, 2024
@sakalys
Copy link

sakalys commented Jul 3, 2024

Can confirm. This renders doctrine v3 not yet usable when the project is using uuids.

@sakalys
Copy link

sakalys commented Aug 11, 2024

This might be very similar to doctrine/orm#11090

But breaks as well on the ManyToOne side (the mentioned MR solves the opposite OneToMany)

@sakalys
Copy link

sakalys commented Sep 26, 2024

This issue seems to stem from EAGER loading entities. It happens when the parameter is an association that EAGER loads.

class Media
{
    #[ORM\Id, ORM\Column(type: 'uuid_binary'), ORM\GeneratedValue(strategy: 'NONE')]
    private UuidInterface $id;
class MediaUploadAttempt
{
    #[ORM\ManyToOne(targetEntity: Media::class, fetch: 'EAGER')]
    #[ORM\JoinColumn(name: 'media_id', unique: true, nullable: true)]
    private ?Media $uploadedMedia = null;
class MediaUploadAttemptRepository extends ServiceEntityRepository
{
    public function findOneByUploadedMediaId(UuidInterface $mediaId): ?MediaUploadAttempt
    {
        return $this->createQueryBuilder('a')
            ->andWhere('IDENTITY(a.uploadedMedia) = :mediaId')
            ->setParameter('mediaId', $mediaId->getBytes())
            ->getQuery()
            ->getOneOrNullResult();
    }

The above conditions produce the error

@sakalys
Copy link

sakalys commented Sep 26, 2024

The more I look into this, the more I see that this is not an issue of ramsey/uuid-doctrine, but rather doctrine/orm

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

No branches or pull requests

2 participants