<i id='NW7Yv'><tr id='NW7Yv'><dt id='NW7Yv'><q id='NW7Yv'><span id='NW7Yv'><b id='NW7Yv'><form id='NW7Yv'><ins id='NW7Yv'></ins><ul id='NW7Yv'></ul><sub id='NW7Yv'></sub></form><legend id='NW7Yv'></legend><bdo id='NW7Yv'><pre id='NW7Yv'><center id='NW7Yv'></center></pre></bdo></b><th id='NW7Yv'></th></span></q></dt></tr></i><div id='NW7Yv'><tfoot id='NW7Yv'></tfoot><dl id='NW7Yv'><fieldset id='NW7Yv'></fieldset></dl></div>

    1. <legend id='NW7Yv'><style id='NW7Yv'><dir id='NW7Yv'><q id='NW7Yv'></q></dir></style></legend>
      <tfoot id='NW7Yv'></tfoot>

    2. <small id='NW7Yv'></small><noframes id='NW7Yv'>

        • <bdo id='NW7Yv'></bdo><ul id='NW7Yv'></ul>

        Twig 和 Symfony2 - 未找到实体

        时间:2023-08-19

                <tbody id='qa5Eh'></tbody>
            • <legend id='qa5Eh'><style id='qa5Eh'><dir id='qa5Eh'><q id='qa5Eh'></q></dir></style></legend>
                <tfoot id='qa5Eh'></tfoot>
                <i id='qa5Eh'><tr id='qa5Eh'><dt id='qa5Eh'><q id='qa5Eh'><span id='qa5Eh'><b id='qa5Eh'><form id='qa5Eh'><ins id='qa5Eh'></ins><ul id='qa5Eh'></ul><sub id='qa5Eh'></sub></form><legend id='qa5Eh'></legend><bdo id='qa5Eh'><pre id='qa5Eh'><center id='qa5Eh'></center></pre></bdo></b><th id='qa5Eh'></th></span></q></dt></tr></i><div id='qa5Eh'><tfoot id='qa5Eh'></tfoot><dl id='qa5Eh'><fieldset id='qa5Eh'></fieldset></dl></div>

                  <bdo id='qa5Eh'></bdo><ul id='qa5Eh'></ul>

                  <small id='qa5Eh'></small><noframes id='qa5Eh'>

                  本文介绍了Twig 和 Symfony2 - 未找到实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个与其他一些实体相关的实体.最后,我有一个像 tat 这样的对象:

                  I have an entity that is related to some other entities. On the end, I have an object like tat:

                  paper.submission.authors
                  

                  对于一些paper.submission,没有作者,在我的twig模板中,我在做:

                  For some of the paper.submission, there is no author, and in my twig template, I am doing:

                  {% for author in paper.submission.authors}
                      do something
                  {% endfor %}
                  

                  对于没有作者的 paper.submission,我收到实体未找到"异常.

                  And for the paper.submission with no authors, I am getting "Entity was not found" exception.

                  你是否有可能在我的 for 循环之前测试对象是否存在.

                  Is thee any possibility to test if the object exists before my for loop.

                  我尝试过定义,它总是正确的.然后,我尝试过不为空,但这也会产生异常.

                  I have try the is defined, it is always true. Then, I have tryed is not null, but this is also generating the exception.

                  非常感谢您.

                  推荐答案

                  问题

                  Doctrine 在找不到相关实体时抛出此异常.这样说似乎多余,但实际上这很重要.
                  这意味着它可以找到与之相关的 ID,但是提出的请求原则与任何结果都不匹配.

                  Problem

                  Doctrine throws this Exception when it doesn't find the related entity. It seems redundant to say this, but in fact this is important.
                  It means it could find an ID related to it, but the request doctrine made didn't match any result.

                  我的猜测是您的数据库表(实际上是链接表)submission.authors 包含 0 而不是 NULL 的 ID.
                  这样,Doctrine 认为IS 有一个 ID 为 0 的作者,因此找不到它.

                  My guess is that your database table (link table actually) submission.authors contains IDs of 0 instead of NULL.
                  With such, Doctrine thinks there IS an author with ID of 0, and therefor, cannot find it.

                  submission.authors 始终存在.它是一个 未初始化 Doctrine 代理.

                  submission.authors always exists. It is an Uninitialized Doctrine Proxy.

                  var_dump($submission->getAuthors());
                  

                  会告诉你什么包含了 submission.authors
                  此时,不进行任何查询.它只是返回一个 PersistentCollection 带有标志 isInitialized 为假.

                  Would show you what contains exactly submission.authors
                  At this point, no queries are made. It simply returns a PersistentCollection with a flag isInitialized to false.

                  当您尝试从中获取属性时会发生异常

                  The exception occurs when you're trying to get a property out of it

                  foreach ($submission->getAuthors() as $author) {
                  }
                  

                  执行此操作时将检查 getAuthors 是否已初始化.如果没有,它将运行以下查询

                  When doing this doctrine will check if getAuthors is initialized. If not, it will run the following query

                  SELECT <stuffs> FROM authors WHERE id = 0;
                  

                  不返回匹配项并抛出 EntityNotFound 异常

                  Which returns no match and will throw an EntityNotFound Exception

                  您必须将 id 行的默认值设置为 NULL 并进行查询以将所有 0 更新为 NULL.
                  有了这个,您可以轻松地使用 is not null

                  You must set your id row's default to NULL and make a query to update all 0's to NULL.
                  With this, you can easily test submission.authors with is not null

                  Doctrine 如果发现 NULL

                  Doctrine will not run any query if it finds a NULL

                  这篇关于Twig 和 Symfony2 - 未找到实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用查询构建器删除 Doctrine 2 下一篇:原则 2:在批处理插入引用其他实体的实体时出现奇怪的行为

                  相关文章

                  <legend id='mLKS5'><style id='mLKS5'><dir id='mLKS5'><q id='mLKS5'></q></dir></style></legend>
                • <i id='mLKS5'><tr id='mLKS5'><dt id='mLKS5'><q id='mLKS5'><span id='mLKS5'><b id='mLKS5'><form id='mLKS5'><ins id='mLKS5'></ins><ul id='mLKS5'></ul><sub id='mLKS5'></sub></form><legend id='mLKS5'></legend><bdo id='mLKS5'><pre id='mLKS5'><center id='mLKS5'></center></pre></bdo></b><th id='mLKS5'></th></span></q></dt></tr></i><div id='mLKS5'><tfoot id='mLKS5'></tfoot><dl id='mLKS5'><fieldset id='mLKS5'></fieldset></dl></div>
                • <small id='mLKS5'></small><noframes id='mLKS5'>

                      <bdo id='mLKS5'></bdo><ul id='mLKS5'></ul>
                    1. <tfoot id='mLKS5'></tfoot>