doctrine-orm – Symfony:为什么isInitialized始终是假的?

我用doctrine查询用户:

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

但我得到了结果:

Customer {#1441 ▼
+isInitialized: false
-id: 1
-username: null
-nickname: null
-email: null
-salt: null
-password: null
-roles: null
-enabled: null
-lastLogin: null
-expired: null
-expiredAt: null
-created: null
-modified: null
-group: null
-ceilphoneCode: null
-avatar: null
-tasks: null
-applications: null
-companies: null
-creators: null
-images: null
-company: null
-store: Store {#1440 ▶}
-realName: null
-sex: null
-age: null
-belongCompany: null
-address: null
-career: null
-relationProducts: null
-attributes: null
-medias: null
-logs: null
…2
}

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

最佳答案 isInitialized为false,因为您从EntityManager获取Proxy对象.您可能在应用程序之前的某个位置加载了一个ID为1的Customer作为关联的实体.此相关对象未加入连接(未加载),因此现在从您的EntityManager返回相同的代理.通常find应返回一个完全加载的对象.

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

点赞