<bdo id='7eqS8'></bdo><ul id='7eqS8'></ul>

    <small id='7eqS8'></small><noframes id='7eqS8'>

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

      1. Doctrine - OneToMany 关系,所有结果行不获取对象

        Doctrine - OneToMany relation, all result row doesn#39;t fetch in object(Doctrine - OneToMany 关系,所有结果行不获取对象)

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

                <tbody id='vLKFa'></tbody>

              • <legend id='vLKFa'><style id='vLKFa'><dir id='vLKFa'><q id='vLKFa'></q></dir></style></legend>
                <tfoot id='vLKFa'></tfoot>
                • 本文介绍了Doctrine - OneToMany 关系,所有结果行不获取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试获取我的所有对象 DemandCab 及其子对象 (DecisionCab).

                  I try to get all my objects DemandCab with their children object (DecisionCab).

                  我的 2 个实体

                  /**
                   * DemandCab.
                   *
                   * @ORMTable()
                   * @ORMEntity(repositoryClass="DemandCabRepository")
                   */
                  class DemandCab
                  {
                      /**
                       * @var int
                       *
                       * @ORMColumn(name="id", type="integer")
                       * @ORMId
                       * @ORMGeneratedValue(strategy="AUTO")
                       */
                       private $id;
                  
                      /**
                       * @var DecisionCab
                       *
                       * @ORMOneToMany(targetEntity="MyCabBundleEntityDecisionCab", mappedBy="demandCab")
                       */
                       private $decisionsCab;
                  
                      /**
                       * @var DateTime
                       *
                       * @ORMColumn(name="startDate", type="datetime")
                       */
                       private $startDate;
                  
                      /**
                       * @var DateTime
                       *
                       * @ORMColumn(name="endDate", type="datetime", nullable=true)
                       */
                       private $endDate;
                  
                      /**
                       * @var int
                       *
                       * @ORMColumn(name="followup", type="integer", nullable=true)
                       */
                       private $followup;
                  
                      /**
                       * @var InfoCab
                       *
                       * @ORMManyToOne(targetEntity="MyCabBundleEntityInfoCab", inversedBy="demandsCab")
                       */
                       private $infoCab;
                  
                  }
                  
                  /**
                   * DecisionCab.
                   *
                   * @ORMTable()
                   * @ORMEntity(repositoryClass="DecisionCabRepository")
                   */
                   class DecisionCab
                   {
                       /**
                        * @var int
                        *
                        * @ORMColumn(name="id", type="integer")
                        * @ORMId
                        * @ORMGeneratedValue(strategy="AUTO")
                       */
                      private $id;
                  
                       /**
                        * @var DemandCab
                        *
                        * @ORMManyToOne(targetEntity="MyCabBundleEntityDemandCab", inversedBy="decisionsCab")
                        */
                       private $demandCab;
                  
                      /**
                       * @var bool
                       *
                       * @ORMColumn(name="decision", type="boolean", nullable=true)
                       */
                       private $decision;
                  
                      /**
                       * @var string
                       *
                       * @ORMColumn(name="motif", type="string", length=500, nullable=true)
                       */
                       private $motif;
                  
                      /**
                       * @var string
                       *
                       * @ORMColumn(name="role", type="string", length=255)
                       */
                       private $role;
                  
                      /**
                       * @var DateTime
                       *
                       * @ORMColumn(name="date", type="datetime", nullable=true)
                       */
                       private $date;
                  
                      /**
                       * @var DemandCab
                       *
                       * @ORMManyToOne(targetEntity="MyCabBundleEntityDemandCab", inversedBy="decisionsCab")
                       */
                       private $demandCab;
                  
                      /**
                       * @var User
                       *
                       * @ORMManyToOne(targetEntity="MyCabBundleEntityUser", inversedBy="decisionsCab")
                       */
                      private $user;
                  }
                  

                  在我的 DemandCabRepository 中

                  In my DemandCabRepository

                  public function findAllCompleted(){
                      $qb = $this->createQueryBuilder("dem");
                      $qb->select('dem, dec');
                      $qb->leftJoin("dem.decisionsCab", "dec");
                      $qb->andWhere("dem.completed = 1");
                      $qb->orderBy("dem.startDate", "DESC");
                  
                      return $qb->getQuery()->getResult();
                  }
                  

                  我的 DemandCab 数据

                  My DemandCab data

                  我的 DecisionCab 数据

                  My DecisionCab data

                  当我转储结果时,只出现 2 个决定...

                  When i dump result, only 2 decisions appear ...

                  ... 而当我使用 getArrayResult 时,我有 4 个决定...

                  ... whereas when i use getArrayResult, i have my 4 decisions ...

                  查询很好,但我不明白为什么水合删除具有属性 decision 为 0 或 1 的 DecisionCab 对象(仅显示 null).

                  The query is good but i dont understand why hydration remove DecisionCab object with attribute decision at 0 or 1 (only null are display).

                  我想了解为什么以及是否有解决方案来获取包含所有 DecisionCab 子对象的 DemandCab 对象.

                  I would like to understand why and is there a solution to get DemandCab object with all DecisionCab children object.

                  谢谢

                  推荐答案

                  我能够重现您的问题,但我不确定您是否属于这种情况.

                  I am able to reproduce your issue, but I am not sure if this is your case.

                  无论如何,我的假设是您在查询构建器的帮助下至少查询一次与 decision 关系连接的 demand 实体.也许这是在您的操作、事件侦听器或代码中的其他地方完成的.

                  Anyway, my assumption is that you query the demand Entity joined with decision relation at least once with the help of a query builder. Maybe this is done in your action, in an event listener or somewhere else in your code.

                  所以你可能有类似的东西:

                  So you may have something like:

                  $qb = $this->getDoctrine()
                          ->getRepository(DemandCab::class)->createQueryBuilder("dem");
                  $qb->select('dem, dec');
                  $qb->leftJoin("dem.decisionsCab", "dec");
                  
                  $qb->andWhere("dec.decision IS NULL");
                  $qb->orderBy("dem.startDate", "DESC");
                  
                  $results = $qb->getQuery()->getResult(); // <-- the decisionsCab collection is hydrated but filtered
                  
                  $qb2 = $this->getDoctrine()
                          ->getRepository(DemandCab::class)->createQueryBuilder("dem");
                  $qb2->select('dem, dec');
                  $qb2->leftJoin("dem.decisionsCab", "dec");
                  
                  $qb2->andWhere("dem.completed = 1");
                  $qb2->orderBy("dem.startDate", "DESC");
                  
                      $q = $qb2->getQuery();
                      //$q->setHint(Query::HINT_REFRESH, true);
                  
                      $results = $q->getResult();
                  

                  问题出在 DoctrineORMInternalHydrationObjectHydrator 中,它具有属性initializedCollections",其中保存了已初始化的集合,并且集合由父实体类型和实体本身.不幸的是,在上述情况下,heydrator 不明白该集合在第一个查询中被过滤并在第二个查询中使用它以避免补液.(github链接)

                  The issue is in DoctrineORMInternalHydrationObjectHydrator, it has the property "initializedCollections" where already initialized collections are kept and the collections are hashed by the parent entity type and the entity itself. Unfortunately in the above case, the heydrator does not understand that the collection is filtered in the 1st query and uses it in the 2nd query in order to avoid rehydration.(github link)

                  解决方案是让查询生成器刷新.试试代码:

                  The solution is to cause the query builder to refresh. Try the code:

                  $qb->orderBy("dem.startDate", "DESC");
                  $q = $qb->getQuery();
                  $q->setHint(Query::HINT_REFRESH, true);    // <-- Tell the hydrator to refresh
                  return $q->getResult();
                  

                  这篇关于Doctrine - OneToMany 关系,所有结果行不获取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  When should use doctrine ORM and when zend-db-table?(什么时候应该使用学说 ORM,什么时候应该使用 zend-db-table?)
                  Doctrine - self-referencing entity - disable fetching of children(Doctrine - 自引用实体 - 禁用获取子项)
                  Doctrine 2, query inside entities(原则 2,实体内部查询)
                  Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
                  Doctrine and unrefreshed relationships(教义和未更新的关系)
                  How does Doctrine 2 retrieve entities without calling the entity#39;s constructor?(Doctrine 2 如何在不调用实体构造函数的情况下检索实体?)
                      <legend id='FDVa9'><style id='FDVa9'><dir id='FDVa9'><q id='FDVa9'></q></dir></style></legend>

                          <bdo id='FDVa9'></bdo><ul id='FDVa9'></ul>
                            <tbody id='FDVa9'></tbody>
                          <tfoot id='FDVa9'></tfoot>

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