• <tfoot id='gnEly'></tfoot>
    <legend id='gnEly'><style id='gnEly'><dir id='gnEly'><q id='gnEly'></q></dir></style></legend>

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

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

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

      1. Doctrine QueryBuilder 删除连接

        时间:2023-08-19

          <tfoot id='81PGu'></tfoot>

          <small id='81PGu'></small><noframes id='81PGu'>

            <tbody id='81PGu'></tbody>
            <bdo id='81PGu'></bdo><ul id='81PGu'></ul>
                  <i id='81PGu'><tr id='81PGu'><dt id='81PGu'><q id='81PGu'><span id='81PGu'><b id='81PGu'><form id='81PGu'><ins id='81PGu'></ins><ul id='81PGu'></ul><sub id='81PGu'></sub></form><legend id='81PGu'></legend><bdo id='81PGu'><pre id='81PGu'><center id='81PGu'></center></pre></bdo></b><th id='81PGu'></th></span></q></dt></tr></i><div id='81PGu'><tfoot id='81PGu'></tfoot><dl id='81PGu'><fieldset id='81PGu'></fieldset></dl></div>
                1. <legend id='81PGu'><style id='81PGu'><dir id='81PGu'><q id='81PGu'></q></dir></style></legend>
                2. 本文介绍了Doctrine QueryBuilder 删除连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Doctrine QueryBuilder 来执行以下 SQL 查询:

                  I'm trying to use the Doctrine QueryBuilder to perform the following SQL query:

                  DELETE php FROM product_hole_pattern php
                  INNER JOIN hole_pattern hp ON php.hole_pattern_id = hp.id
                  INNER JOIN hole_pattern_type hpt ON hp.hole_pattern_type_id = hpt.id
                  WHERE php.product_id = 4 AND hpt.slug='universal';
                  

                  我有这个

                  $qb = $this->entityManager->createQueryBuilder();
                  $query = $qb->delete('SANUSEntityProductHolePattern', 'php')
                    ->innerJoin('php.holePattern', 'hp')
                    ->innerJoin('hp.holePatternType', 'hpt')
                    ->where('hpt.slug = :slug AND php.product=:product')
                    ->setParameter('slug','universal')
                    ->setParameter('product',$this->id)
                    ->getQuery();
                  

                  但我明白了:

                  [Semantical Error] line 0, col 50 near 'hpt.slug = :slug': Error: 'hpt' is not defined.
                  

                  错误信息自带的DQL是:

                  The DQL that comes with the error message is:

                  DELETE SANUSEntityProductHolePattern php 
                  WHERE hpt.slug = :slug AND php.product=:product
                  

                  所以连接似乎被完全省略了.

                  So the joins seem to be omitted completely.

                  推荐答案

                  使用 IN 条件运行查询可能比迭代更好.

                  It may be better to run a query with IN condition rather than iterating.

                  $ids = $this->createQueryBuilder('product')
                  ->join('..your joins..')
                  ->where('..your wheres..')
                  ->select('product.id')
                  ->getQuery()->getResult();
                  
                  $this->createQueryBuilder('product')
                      ->where('product.id in (:ids)')
                      ->setParameter('ids', $ids)
                      ->delete()
                      ->getQuery()
                      ->execute();
                  

                  • 优点:运行速度更快,无需迭代
                  • 缺点:你不能挂钩 preRemove
                  • 至于把它放在哪里"的激烈争论,如果你愿意,敢于把它放在控制器中.这完全取决于你.但是,如果您将代码放在专用的学说存储库类中,那么将来可能对您更有用.它应该很容易做到,并且易于更改/维护.

                    As to heated "where to put it" debate, dare to put it in the controller if you like. That's completely up to you. However, it may be more useful to you in the future if you land the code in the dedicated doctrine repository class. It should be very easy to do and makes it easy to change / maintain.

                    这篇关于Doctrine QueryBuilder 删除连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:不调用具有抽象基类的 Doctrine 2 LifecycleCallbacks 下一篇:如何在学说 2 实体的存储库中使用复杂的标准?

                  相关文章

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

                    1. <small id='affs3'></small><noframes id='affs3'>

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

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