How do you get the associated object id without loading the associated object?

Consider an object with manyToOne one-way association:

EntityX:
    type: entity
    table: x
    id:
        id:
            type: integer
            generator: { strategy: AUTO }

    fields:
        type:
            type: string

    manyToOne:
        entityY:
            targetEntity: EntityY

      

Any EntityY property will be loaded lazily through the proxy class; however, the EntityY will (should) be available before the proxy is loaded. What is the best way to get this ID without running the EntityY proxy loader?

Edit: I'm using Symfony2 (2.0.11) so Doctrine dependency is limited to v2.1

+3


source to share


1 answer


Short answer: Moving to doctrine 2.2. EntityY-> getId () will no longer trigger class loading.



I've seen code for a long time that showed how to get to the UnitOfWork object and pull it out. I can not find. You can try to find the Doctrine2 users mailing list. But given that 2.2 fixes this issue, I'll just live with the download until I can upgrade.

+6


source







All Articles