Entity of type #39;AppBundleEntityUser#39; for IDs id(155) was not found(找不到 ID id(155) 的类型为“AppBundleEntityUser的实体)
问题描述
当我遍历一个组的用户(组#users,它是多对一关系)以显示用户电子邮件时,我收到此错误 Entity of type 'AppBundleEntityUser' for IDs id(155)找不到
.但是,当我显示引发异常的用户时,我会看到:
When I iterate over users of one group (group#users and it's a ManyToOne relationship) to display the users emails, I get this error Entity of type 'AppBundleEntityUser' for IDs id(155) was not found
. However, when I display the user for which the exception is raised I see this:
// In my controller
dump($groups[0]->getUser());
// Output
User {#761 ▼
+__isInitialized__: false
#id: 155
#email: null
#firstName: null
#lastName: null
#roles: null
…2
}
此外,此用户(其 id 等于 155)确实存在于我的数据库中.
Besides, this user (whose id equals 155) does exist in my database.
更新 1
public function getByCriteria(array $criteria)
{
$qb = $this->createQueryBuilder('g');
// ....
return $qb
->getQuery()
// This does NOT change anything ?? Isn't this supposed to load related user??
// http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#temporarily-change-fetch-mode-in-dql
->setFetchMode('class_namespace', 'user', ClassMetadata::FETCH_EAGER)
->getResult();
}
推荐答案
想通了!!实际上有一个启用的学说过滤器在每个 sql 查询中添加一个条件.当我得到一个组时,与其相关的用户不会从数据库中加载,只有它的 id 与组实体一起加载.当我尝试访问 id 以外的其他用户字段时,它会执行 sql join 查询.同样,学说过滤器将条件添加到连接条件中,这会导致结果为空.
Figured it out!! Actually there is a an enabled doctrine filter that adds one condition in every sql query. When I get one group, the user being related to it is not loaded from the database, only its id is loaded with the group entity. When I try to access other user field than the id, it performs the sql join query. Again, the doctrine filter adds the condition even to the join condition, which leads to an empty result.
所以错误信息显然具有误导性.
So the error message is clearly misleading.
这篇关于找不到 ID id(155) 的类型为“AppBundleEntityUser"的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:找不到 ID id(155) 的类型为“AppBundleEntityUser"的实体


基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01