Cannot filter query by embedded columns #6603

Closed
opened 2026-01-22 15:35:35 +01:00 by admin · 1 comment
Owner

Originally created by @rkonopski on GitHub (Jan 14, 2021).

Hi, I cannot filter query by embedded columns. Any other columns than embedded type are working well.

Interestingly that embedded object is correctly saved in database. I can save it, but I cannot filter. I've tried with many combinations: r.activation.code, r.activation_code, r.activation_code_code, r.activation_code.code. Moreover even PhpStorm doesn't show any hint about these embedded columns.

Entity:

    /**
     * @ORM\Embedded(class="Example\ValueObject\ActivationCode", columnPrefix="activation_")
     */
    private ActivationCode $activationCode;

Embedded object:

    /**
     * @ORM\Column(type="datetime")
     */
    private DateTimeInterface $expirationDateTime;

    /**
     * @ORM\Column(type="uuid", unique=true)
     */
    private string $code;

Query:

    public function isActivationCodeExists(string $activationCode): bool
    {
        return (bool)$this->createQueryBuilder('r')
            ->where('r.activation.code = :activationCode')
            ->setParameter('activationCode', $activationCode, 'uuid')
            ->getQuery()
            ->getOneOrNullResult();
    }

Query throwing an error:

[Semantical Error] line 0, col 87 near 'code = :acti': Error: Class Example\Entity\Registration has no field or association named activation.code

Database columns:

id
activation_code
activation_date
activation_expiration_date_time
Originally created by @rkonopski on GitHub (Jan 14, 2021). Hi, I cannot filter query by embedded columns. Any other columns than embedded type are working well. Interestingly that embedded object is correctly saved in database. I can save it, but I cannot filter. I've tried with many combinations: `r.activation.code`, `r.activation_code`, `r.activation_code_code`, `r.activation_code.code`. Moreover even PhpStorm doesn't show any hint about these embedded columns. Entity: ``` /** * @ORM\Embedded(class="Example\ValueObject\ActivationCode", columnPrefix="activation_") */ private ActivationCode $activationCode; ``` Embedded object: ``` /** * @ORM\Column(type="datetime") */ private DateTimeInterface $expirationDateTime; /** * @ORM\Column(type="uuid", unique=true) */ private string $code; ``` Query: ``` public function isActivationCodeExists(string $activationCode): bool { return (bool)$this->createQueryBuilder('r') ->where('r.activation.code = :activationCode') ->setParameter('activationCode', $activationCode, 'uuid') ->getQuery() ->getOneOrNullResult(); } ``` Query throwing an error: ``` [Semantical Error] line 0, col 87 near 'code = :acti': Error: Class Example\Entity\Registration has no field or association named activation.code ``` Database columns: ``` id activation_code activation_date activation_expiration_date_time ```
admin closed this issue 2026-01-22 15:35:35 +01:00
Author
Owner

@rkonopski commented on GitHub (Jan 15, 2021):

I've found that just mapping was wrong. In \Doctrine\ORM\Query\Parser::processDeferredPathExpressions method we can see valid mappings: $class->fieldMappings

@rkonopski commented on GitHub (Jan 15, 2021): I've found that just mapping was wrong. In` \Doctrine\ORM\Query\Parser::processDeferredPathExpressions` method we can see valid mappings: `$class->fieldMappings`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6603