Embeddables not correctly compared in WHERE clause of DQL #7209

Open
opened 2026-01-22 15:47:02 +01:00 by admin · 0 comments
Owner

Originally created by @coztymit on GitHub (Aug 9, 2023).

While working with Doctrine and its feature of embeddables, I have encountered an issue regarding DQL and the way it treats embedded objects in the WHERE clause.

I've encountered an issue with Doctrine ORM when trying to use an embeddable object in a DQL WHERE clause.

Current Behavior:

When trying to use the following DQL query:

SELECT i FROM Identity i WHERE i.email = :email

where email is an embeddable object, Doctrine doesn't seem to handle the comparison of the whole embeddable object.

To get it to work, I currently have to access the individual fields of the embeddable object:

SELECT i FROM Identity i WHERE i.email.value = :email->value()

Expected Behavior:

Ideally, Doctrine ORM should be able to handle the comparison of the entire embeddable object in DQL.

Environment:

doctrine/doctrine-bundle: ^2.10
doctrine/doctrine-migrations-bundle: ^3.2
doctrine/orm: ^2.15.4

I hope this issue can be addressed in future releases. Thank you for the great work you do with Doctrine.

<?php

namespace App\Entity;

#[Entity]
#[Table(name: "identities")]
class Identity
{
    #[Id, GeneratedValue, Column(type: "integer")]
    private int $id;

    #[Embedded(class: "Email", columnPrefix: false)]
    private Email $email;
}

#[Embeddable]
class Email
{
    #[Column(type: "string", length: 255)]
    private string $value;
}
Originally created by @coztymit on GitHub (Aug 9, 2023). While working with Doctrine and its feature of embeddables, I have encountered an issue regarding DQL and the way it treats embedded objects in the WHERE clause. I've encountered an issue with Doctrine ORM when trying to use an embeddable object in a DQL `WHERE` clause. ### Current Behavior: When trying to use the following DQL query: `SELECT i FROM Identity i WHERE i.email = :email` where email is an embeddable object, Doctrine doesn't seem to handle the comparison of the whole embeddable object. To get it to work, I currently have to access the individual fields of the embeddable object: `SELECT i FROM Identity i WHERE i.email.value = :email->value()` ## Expected Behavior: Ideally, Doctrine ORM should be able to handle the comparison of the entire embeddable object in DQL. ## Environment: doctrine/doctrine-bundle: ^2.10 doctrine/doctrine-migrations-bundle: ^3.2 doctrine/orm: ^2.15.4 I hope this issue can be addressed in future releases. Thank you for the great work you do with Doctrine. ```php <?php namespace App\Entity; #[Entity] #[Table(name: "identities")] class Identity { #[Id, GeneratedValue, Column(type: "integer")] private int $id; #[Embedded(class: "Email", columnPrefix: false)] private Email $email; } #[Embeddable] class Email { #[Column(type: "string", length: 255)] private string $value; }
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7209