【问题标题】:Symfony: Why the isInitialized always is false?Symfony:为什么 isInitialized 总是错误的?
【发布时间】:2017-06-07 21:09:27
【问题描述】:

我用教义查询一个用户:

$customer = $this->getDoctrine()->getRepository('DemoUserBundle:Customer')->find(1);

但我得到了结果:

客户{#1441 ▼ +isInitialized: false -id:1 -用户名:空 -昵称:空 -电子邮件:空 -盐:空 -密码:空 -角色:空 -启用:空 -lastLogin:空 -过期:空 -expiredAt:空 -创建:空 -修改:空 -组:空 -ceilphoneCode:空 -头像:空 -任务:空 -应用程序:空 -公司:空 -创作者:空 -图像:空 -公司:空 -store: 商店 {#1440 ▶} -realName:空 -性别:空 -年龄:空 -belongCompany:空 -地址:空 -职业:空 -relationProducts:空 -属性:空 -媒体:空 -日志:空 …2 }

结果未完成,该用户的其他数据在哪里?为什么 isInitialized 是假的?

【问题讨论】:

  • 查询数据库中 id=1 时会怎样?

标签: doctrine-orm symfony


【解决方案1】:

我将fetch="EAGER" 添加到另一个调用该实体的实体中,这对我来说没问题。

试试$customer = $this->getDoctrine()->getRepository('DemoUserBundle:Customer')->find(1);

$customer = $this->getDoctrine()->getRepository('DemoUserBundle:Customer')->find(2);

你会明白的。

【讨论】:

    【解决方案2】:

    isInitialized 为 false,因为您从 EntityManager 获得了 Proxy 对象。您可能加载了一个带有Customer 的实体,ID 为1,作为应用程序中较早位置的关联。这个相关的对象没有被提取加入(不是急切地加载),因此现在从你的EntityManager 返回相同的Proxy。通常find 应该返回一个完全加载的对象。

    另请阅读this GitHub post,其中讨论了类似问题

    【讨论】:

      猜你喜欢
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-04
      • 1970-01-01
      • 2020-10-16
      • 2021-09-10
      • 2014-01-10
      相关资源
      最近更新 更多