doctrine / orm

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

Embeded property reflection not working #6360

Open ScreamingDev opened 7 years ago

ScreamingDev commented 7 years ago

Hi there. I have an embeded entity like this:

    <entity name="AbcBundle\Entity\Customer"
            table="customer">

        <id name="id" type="bigint">
            <generator strategy="AUTO" />
        </id>

        <embedded name="uuid" use-column-prefix="false" class="\AbcBundle\Entity\CustomerId" />

        <lifecycle-callbacks>
            <!-- Assert writing the UUID for new entities. -->
            <lifecycle-callback type="prePersist" method="getDomainId"/>
        </lifecycle-callbacks>
    </entity>

and

    <embeddable name="AbcBundle\Entity\CustomerId">
        <field name="value" type="string" column="uuid" />
    </embeddable>

but the CustomerId extends another class:

class CusotmerId extends \App\Domain\UserId {}

So every property is defined there. Why does Doctrine/PHP keeps telling me this?

[ReflectionException]
Given object is not an instance of the class this property was declared in

There is something odd with it as you see here:

screen-170326-0173c

What else do you need from me? Seems like I can't work with embeded in my setup. Only works when I remove them.

See my versions here:

doctrine/cache                       v1.6.1
doctrine/collections                 v1.4.0
doctrine/common                      v2.7.2
doctrine/data-fixtures               v1.2.2
doctrine/dbal                        v2.5.12  
doctrine/doctrine-bundle             1.6.7
doctrine/doctrine-cache-bundle       1.3.0
doctrine/doctrine-fixtures-bundle    2.3.0  
doctrine/doctrine-migrations-bundle  v1.2.1
doctrine/inflector                   v1.1.0             
doctrine/instantiator                1.0.5       
doctrine/lexer                       v1.0.1     
doctrine/migrations                  v1.5.0 
doctrine/orm                         v2.5.6    
theofidry commented 7 years ago

Not sure if that occurs everywhere, but FYI you should use custom types rather than embedded classes for your custom IDs.

Ocramius commented 7 years ago

The customer id is probably a class that extends a UUID with a private ID, right? If that's what is mapped, then the ID property doesn't exist in the child CustomerId class (that's normal, since it's not visible). Doctrine has no way to have you inherit properties from parent embeddable classes, so you will either need to move the field to CustomerId or make it protected.

On 26 Mar 2017 9:16 a.m., "Théo FIDRY" notifications@github.com wrote:

Not sure if that occurs everywhere, but FYI you should use custom types rather than embedded classes for your custom IDs.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/doctrine/doctrine2/issues/6360#issuecomment-289287317, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakGTBFh1RWED3AtVVbS6PJYSXzyg5ks5rpnNJgaJpZM4MpZT6 .

ostrolucky commented 6 years ago

@ScreamingDev given feedback from other users, did you solve the issue? Can we close?