如何在不加载关联实体的情况下获取关联实体的 id? [英] How do you get an associated entity's id without loading the associated entity?

查看:23
本文介绍了如何在不加载关联实体的情况下获取关联实体的 id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个具有(单向)manyToOne 关联的实体:

Consider an entity with a (unidirectional) manyToOne association:

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

    fields:
        type:
            type: string

    manyToOne:
        entityY:
            targetEntity: EntityY

EntityY 的任何属性都将通过代理类延迟加载;但是,EntityY 的标识符将(必须)在代理加载之前可用.在不触发 EntityY 的代理加载器的情况下获取此标识符的最佳方法是什么?

Any property of EntityY will be lazy loaded via a proxy class; however, EntityY's identifier will be (has to be) available before the proxy load. What is the best way to get at this identifier without triggering EntityY's proxy loader?

我使用的是 Symfony2 (2.0.11),所以 Doctrine 依赖被限制为 v2.1

I'm using Symfony2 (2.0.11) so the Doctrine dependency is constrained to v2.1

推荐答案

简答:升级到 Doctrine 2.2.EntityY->getId() 将不再触发类的加载.

Short answer: Upgrade to Doctrine 2.2. EntityY->getId() will no longer trigger loading of the class.

很久以前我确实看到过一些代码,它展示了如何进入 UnitOfWork 对象并将其拉出.找不到.可以尝试搜索 Doctrine2 用户邮件列表.但是考虑到 2.2 修复了这个问题,我只能忍受加载直到我可以升级.

I did see some code a long time ago which showed how to reach into the UnitOfWork object and pull this out. Can't find it. Might try searching the Doctrine2 user mailing list. But given that 2.2 fixes this problem, I would just live with the loading until I could upgrade.

这篇关于如何在不加载关联实体的情况下获取关联实体的 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆