<legend id='Mtx4I'><style id='Mtx4I'><dir id='Mtx4I'><q id='Mtx4I'></q></dir></style></legend>

        <bdo id='Mtx4I'></bdo><ul id='Mtx4I'></ul>
    1. <small id='Mtx4I'></small><noframes id='Mtx4I'>

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

        Doctrine2:不能通过标识变量选择实体而不选择至少一个根实体别名

        Doctrine2: Cannot select entity through identification variables without choosing at least one root entity alias(Doctrine2:不能通过标识变量选择实体而不选择至少一个根实体别名)

            <tbody id='JEzpl'></tbody>

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

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

                  本文介绍了Doctrine2:不能通过标识变量选择实体而不选择至少一个根实体别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我被一个最初非常简单的学说 2 查询困住了.我有一个名为 Category 的实体,它与自身具有 OneToMany 关系(对于父类和子类).

                  I am stuck with an originally very simple doctrine 2 query. I have an entity called Category which has a OneToMany relation with itself (for parent and child categories).

                  /**
                   * @ORMManyToOne(targetEntity="Category", inversedBy="children")
                   */
                  private $parent;
                  
                  /**
                   * @ORMOneToMany(targetEntity="Category", mappedBy="parent")
                   */
                  private $children;
                  

                  以下查询

                  $q = $this->createQueryBuilder('c')
                              ->leftJoin('c.children', 'cc')
                              ->select('c.name as title, cc')
                              ->where('c.parent IS NULL');
                  

                  因错误而失败

                  如果不选择至少一个根实体别名,则无法通过标识变量选择实体.

                  Cannot select entity through identification variables without choosing at least one root entity alias.

                  我真的不明白这个问题.如果我省略了 ->select 部分,则查询确实有效并给出了预期的结果.我已经搜索了论坛,但找不到解决方案,这很有效.有人有建议吗?非常感谢.

                  I don't really get the issue. If I omit the ->select part, the query does work and gives the expected result. I have already searched the forum but couldn't find a solution, that worked. Does anyone have a suggestion? Thanks a lot.

                  推荐答案

                  您的问题是您试图从 Category 实体中选择一个字段,同时选择加入的 Category 实体的整个对象.与普通 SQL 不同,使用 QueryBuilder 组件,您不能仅从要加入的表中选择实体.

                  Your issue is that you are trying to select one field from the Category entity while simultaneously selecting the entire object of the joined Category entity. Unlike plain SQL, with the QueryBuilder component you can't select an entity only from the table you are joining on.

                  如果您希望返回带有连接子项的主 Category 对象,您可以执行 ->select(array('c', 'cc')),或者直接省略->select() 完全调用.前者将在单个查询中自动选择您需要的孩子.如果您想访问主类别实体上的子项,后者将需要另一个 SQL 查询.

                  If you are looking to return your main Category object with the joined children, you can either do ->select(array('c', 'cc')), or simply omit the ->select() call altogether. The former will automatically select the children you need in a single query. The latter will require another SQL query if you want to access children on the main Category entity.

                  如果出于某种原因您希望 name 在您的对象中选择为 title,您可以随时向您的实体添加另一个函数,作为检索名称的别名而不必将其写在您的查询中:

                  If there is a reason you want name to select as title in your object, you can always add another function to your entity that is an alias for retrieving the name instead of having to write it in your query:

                  function getTitle()
                  {
                      return $this->getName();
                  }
                  

                  这篇关于Doctrine2:不能通过标识变量选择实体而不选择至少一个根实体别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <tfoot id='C5keE'></tfoot>

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

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

                              <tbody id='C5keE'></tbody>