• <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 删除连接

        Doctrine QueryBuilder delete with joins(Doctrine QueryBuilder 删除连接)

          <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 删除连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                  <legend id='affs3'><style id='affs3'><dir id='affs3'><q id='affs3'></q></dir></style></legend>

                      <tbody id='affs3'></tbody>
                      • <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>