Processes an individual parameter value with embeddables #6422

Open
opened 2026-01-22 15:32:56 +01:00 by admin · 9 comments
Owner

Originally created by @amelendres on GitHub (Mar 10, 2020).

Bug Report

Q A
BC Break yes
Version 2.7.1

Summary

Queries with embeddable parameters has an error.
trying to access to a hardcoded undefined index 0.

message = "Notice: Undefined offset: 0"
line = {int} 730
file = "/app/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php"
severity = {int} 8
Exceptionstring = ""
code = {int} 0

trace:
file = "/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php"
line = {int} 424
function = "getSingleIdentifierValue"
class = "Doctrine\ORM\UnitOfWork"
type = "->"

Current behavior

Imposible to create a query with query builder using embeddable value objects.

How to reproduce

  1. map an entity with embeddable value objects
  2. update the schema database
  3. create a custom query with QueryBuilder
  4. query->getResults
  5. ErrorException Notice: Undefined offset: 0

Expected behavior

execute the query

Screen Shot 2020-03-10 at 13 42 26

Originally created by @amelendres on GitHub (Mar 10, 2020). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes | Version | 2.7.1 #### Summary Queries with embeddable parameters has an error. trying to access to a hardcoded undefined index 0. message = "Notice: Undefined offset: 0" line = {int} 730 file = "/app/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php" severity = {int} 8 *Exception*string = "" code = {int} 0 **trace:** file = "/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php" line = {int} 424 function = "getSingleIdentifierValue" class = "Doctrine\ORM\UnitOfWork" type = "->" #### Current behavior Imposible to create a query with query builder using embeddable value objects. #### How to reproduce 1. map an entity with embeddable value objects 2. update the schema database 3. create a custom query with QueryBuilder 4. query->getResults 5. ErrorException `Notice: Undefined offset: 0` #### Expected behavior execute the query ![Screen Shot 2020-03-10 at 13 42 26](https://user-images.githubusercontent.com/1708652/76313333-0898a900-62d5-11ea-84e0-ff3c2645694b.png)
Author
Owner

@SenseException commented on GitHub (Mar 10, 2020):

Please add your DQL Query and involved entities + mappings that is causing this error.

@SenseException commented on GitHub (Mar 10, 2020): Please add your DQL Query and involved entities + mappings that is causing this error.
Author
Owner

@amelendres commented on GitHub (Mar 10, 2020):

DQL:
SELECT a FROM Appto\Booking\Domain\Availability\Availability a WHERE a.boatId.value = :boatId AND a.portId.value = :portId AND ((a.timePeriod.startDate BETWEEN :start AND :end) OR (a.timePeriod.endDate BETWEEN :start AND :end)) ORDER BY a.timePeriod.startDate ASC

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Appto\Booking\Domain\Availability\Availability" table="boo_availability" >
        <embedded name="id" class="Appto\Booking\Domain\Availability\AvailabilityId" use-column-prefix="false"/>
        <embedded name="boatId" class="Appto\Booking\Domain\Availability\BoatId" use-column-prefix="false"/>
        <embedded name="portId" class="Appto\Booking\Domain\Availability\PortId" use-column-prefix="false"/>
        <embedded name="timePeriod" class="Appto\Common\Domain\DateTime\TimePeriod"/>
        <embedded name="dailyPrice" class="Appto\Common\Domain\Money\Price"/>
    </entity>
</doctrine-mapping>


<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
        <embeddable name="Appto\Booking\Domain\Availability\BoatId">
            <field name="value" type="guid" column="boat_id" />
        </embeddable>
</doctrine-mapping>

@amelendres commented on GitHub (Mar 10, 2020): DQL: `SELECT a FROM Appto\Booking\Domain\Availability\Availability a WHERE a.boatId.value = :boatId AND a.portId.value = :portId AND ((a.timePeriod.startDate BETWEEN :start AND :end) OR (a.timePeriod.endDate BETWEEN :start AND :end)) ORDER BY a.timePeriod.startDate ASC` ``` <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Appto\Booking\Domain\Availability\Availability" table="boo_availability" > <embedded name="id" class="Appto\Booking\Domain\Availability\AvailabilityId" use-column-prefix="false"/> <embedded name="boatId" class="Appto\Booking\Domain\Availability\BoatId" use-column-prefix="false"/> <embedded name="portId" class="Appto\Booking\Domain\Availability\PortId" use-column-prefix="false"/> <embedded name="timePeriod" class="Appto\Common\Domain\DateTime\TimePeriod"/> <embedded name="dailyPrice" class="Appto\Common\Domain\Money\Price"/> </entity> </doctrine-mapping> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <embeddable name="Appto\Booking\Domain\Availability\BoatId"> <field name="value" type="guid" column="boat_id" /> </embeddable> </doctrine-mapping> ```
Author
Owner

@blackandred commented on GitHub (Sep 10, 2020):

Same there.

SELECT usr FROM App\Domain\Users\WriteModel\User usr WHERE usr.email.value = :email
App\Domain\Users\WriteModel\User:
    type: entity
    table: users

    id:
        id:
            type: guid
            generator:
                strategy: UUID

    embedded:
        email:
            class: App\Domain\Users\ValueObject\Email
            columnPrefix: false

        password:
            class: App\Domain\Users\ValueObject\Password
            columnPrefix: false

        organization:
            class: App\Domain\Users\ValueObject\Organization
            columnPrefix: false

        about:
            class: App\Domain\Users\ValueObject\About
            columnPrefix: false

        roles:
            class: App\Domain\Users\Collection\RolesCollection
            columnPrefix: false

    fields:
        salt:
            type: string
            length: 32

image

Notice: Undefined offset: 0

  at vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:732
  at Doctrine\ORM\Mapping\ClassMetadataInfo->getIdentifierValues()
     (vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3034)
  at Doctrine\ORM\UnitOfWork->getSingleIdentifierValue()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:423)
  at Doctrine\ORM\AbstractQuery->processParameterValue()
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:454)
  at Doctrine\ORM\Query->resolveParameterValue()
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:399)
  at Doctrine\ORM\Query->processParameterMappings()
     (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:328)
  at Doctrine\ORM\Query->_doExecute()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:991)
  at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:946)
  at Doctrine\ORM\AbstractQuery->execute()
     (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:749)
  at Doctrine\ORM\AbstractQuery->getResult()
@blackandred commented on GitHub (Sep 10, 2020): Same there. ```sql SELECT usr FROM App\Domain\Users\WriteModel\User usr WHERE usr.email.value = :email ``` ```yaml App\Domain\Users\WriteModel\User: type: entity table: users id: id: type: guid generator: strategy: UUID embedded: email: class: App\Domain\Users\ValueObject\Email columnPrefix: false password: class: App\Domain\Users\ValueObject\Password columnPrefix: false organization: class: App\Domain\Users\ValueObject\Organization columnPrefix: false about: class: App\Domain\Users\ValueObject\About columnPrefix: false roles: class: App\Domain\Users\Collection\RolesCollection columnPrefix: false fields: salt: type: string length: 32 ``` ![image](https://user-images.githubusercontent.com/22807686/92683889-68c7e080-f334-11ea-8e7c-c6f90e0c4888.png) ``` Notice: Undefined offset: 0 at vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:732 at Doctrine\ORM\Mapping\ClassMetadataInfo->getIdentifierValues() (vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3034) at Doctrine\ORM\UnitOfWork->getSingleIdentifierValue() (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:423) at Doctrine\ORM\AbstractQuery->processParameterValue() (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:454) at Doctrine\ORM\Query->resolveParameterValue() (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:399) at Doctrine\ORM\Query->processParameterMappings() (vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:328) at Doctrine\ORM\Query->_doExecute() (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:991) at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache() (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:946) at Doctrine\ORM\AbstractQuery->execute() (vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:749) at Doctrine\ORM\AbstractQuery->getResult() ```
Author
Owner

@SenseException commented on GitHub (Sep 16, 2020):

@blackandred I have issues to reproduce this error with an no-prefix embeddable. In my tests I get the expected results. Can you please provide an example that can be run and that reproduces this error?

@SenseException commented on GitHub (Sep 16, 2020): @blackandred I have issues to reproduce this error with an no-prefix embeddable. In my tests I get the expected results. Can you please provide an example that can be run and that reproduces this error?
Author
Owner

@blackandred commented on GitHub (Sep 17, 2020):

@blackandred I have issues to reproduce this error with an no-prefix embeddable. In my tests I get the expected results. Can you please provide an example that can be run and that reproduces this error?

I changed something and it is no longer reproducible. I tried now to reproduce it, but no luck. Sorry, I know it would not help.

@blackandred commented on GitHub (Sep 17, 2020): > @blackandred I have issues to reproduce this error with an no-prefix embeddable. In my tests I get the expected results. Can you please provide an example that can be run and that reproduces this error? I changed something and it is no longer reproducible. I tried now to reproduce it, but no luck. Sorry, I know it would not help.
Author
Owner

@SenseException commented on GitHub (Sep 23, 2020):

@blackandred Maybe this issue appears in some combination with a specific version in one of the dependencies. If you can reproduce that state you had, maybe you can get this erroneous behaviour back.

@SenseException commented on GitHub (Sep 23, 2020): @blackandred Maybe this issue appears in some combination with a specific version in one of the dependencies. If you can reproduce that state you had, maybe you can get this erroneous behaviour back.
Author
Owner

@rela589n commented on GitHub (Sep 25, 2020):

I have the same problem!

@rela589n commented on GitHub (Sep 25, 2020): I have the same problem!
Author
Owner

@rela589n commented on GitHub (Sep 25, 2020):

Customer:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="App\Entities\Customer" table="customers">
        <id name="uuid" type="string" column="id">
            <generator strategy="NONE"/>
        </id>

        <embedded name="email" class="App\ValueObjects\Email" use-column-prefix="false"/>
    </entity>
</doctrine-mapping>

Email:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <embeddable name="App\ValueObjects\Email">
        <field name="email" unique="true"/>
    </embeddable>
</doctrine-mapping>

Code that fails:

$repository = EntityManager::getRepository(Customer::class);
$model = $repository->findOneBy(['email.email' => Email::from('admin@email.com')]);
@rela589n commented on GitHub (Sep 25, 2020): Customer: ```xml <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="App\Entities\Customer" table="customers"> <id name="uuid" type="string" column="id"> <generator strategy="NONE"/> </id> <embedded name="email" class="App\ValueObjects\Email" use-column-prefix="false"/> </entity> </doctrine-mapping> ``` Email: ```xml <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <embeddable name="App\ValueObjects\Email"> <field name="email" unique="true"/> </embeddable> </doctrine-mapping> ``` Code that fails: ```php $repository = EntityManager::getRepository(Customer::class); $model = $repository->findOneBy(['email.email' => Email::from('admin@email.com')]); ```
Author
Owner

@rela589n commented on GitHub (Sep 25, 2020):

If I write ['email.email' => 'admin@email.com'], I get no errors.
But wait, isn't there way to search by all fields of value object?
like:

$repository->findOneBy(['email' => Email::from('admin@email.com')])
@rela589n commented on GitHub (Sep 25, 2020): If I write `['email.email' => 'admin@email.com']`, I get no errors. But wait, isn't there way to search by all fields of value object? like: ```php $repository->findOneBy(['email' => Email::from('admin@email.com')]) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6422