找不到ID为ID(155)的'AppBundleundEntity\User'类型的实体 [英] Entity of type 'AppBundle\Entity\User' for IDs id(155) was not found

查看:114
本文介绍了找不到ID为ID(155)的'AppBundleundEntity\User'类型的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我遍历一组用户(group#users,这是一个ManyToOne关系)以显示用户电子邮件时,出现此错误类型为'AppBundle\Entity\User'的实体找不到ID 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 'AppBundle\Entity\User' 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)的'AppBundleundEntity\User'类型的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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