Symfony2和Doctrine - 未定义的索引

Mil*_*loš 7 php entity symfony doctrine-orm twig

我有一个Symfony 2.4.x项目.

在那里,我有两个映射在一起的实体:会议和论文.

每个会议都有论文和特定会议,我想获得论文数量.

为此,在我的会议实体中,我有:

/**
 * @ORM\OneToMany(targetEntity="Paper", mappedBy="conference")
 */
protected $papers;
Run Code Online (Sandbox Code Playgroud)

在实体论文中我有:

/**
 * @ORM\ManyToOne(targetEntity="Conference", inversedBy="papers")
 * @ORM\JoinColumn(name="conference_id", referencedColumnName="id")
 */
protected $conference;
Run Code Online (Sandbox Code Playgroud)

当我在Symfony2.0上有这个项目时,一切都运行良好,但现在我在Symfony 2.4.x中迁移它,我在尝试时遇到以下错误:

count($conf->getPapers()); // In the controller
{{ conf.papers | length }} // In the twig template
Run Code Online (Sandbox Code Playgroud)

错误:

ContextErrorException: Notice: Undefined index: hash_key in /var/www/git/conference2.0-v2.4/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php line 121
Run Code Online (Sandbox Code Playgroud)

编辑:以下是pastebin中两个实体的完整类:

编辑2:这是我通过尝试解决问题找到的一些消息.另有一个classe参与其中:提交.

这是代码:http://pastebin.com/bkdRtjdq

在Submission类中,我有主键是hash_key而不是id.

Geo*_*rge 0

有论文为0的情况吗?conf.papers 变量可能为 null,您需要在计数之前先检查它是否为 null。{% if conf.papers 为空 %} ... {% endif %}