1. <tfoot id='UNCKR'></tfoot>
    2. <small id='UNCKR'></small><noframes id='UNCKR'>

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

        使用查询构建器删除 Doctrine 2

        Doctrine 2 delete with query builder(使用查询构建器删除 Doctrine 2)
      2. <i id='2Rv6v'><tr id='2Rv6v'><dt id='2Rv6v'><q id='2Rv6v'><span id='2Rv6v'><b id='2Rv6v'><form id='2Rv6v'><ins id='2Rv6v'></ins><ul id='2Rv6v'></ul><sub id='2Rv6v'></sub></form><legend id='2Rv6v'></legend><bdo id='2Rv6v'><pre id='2Rv6v'><center id='2Rv6v'></center></pre></bdo></b><th id='2Rv6v'></th></span></q></dt></tr></i><div id='2Rv6v'><tfoot id='2Rv6v'></tfoot><dl id='2Rv6v'><fieldset id='2Rv6v'></fieldset></dl></div>
        <legend id='2Rv6v'><style id='2Rv6v'><dir id='2Rv6v'><q id='2Rv6v'></q></dir></style></legend>
      3. <tfoot id='2Rv6v'></tfoot>

        <small id='2Rv6v'></small><noframes id='2Rv6v'>

              • <bdo id='2Rv6v'></bdo><ul id='2Rv6v'></ul>

                    <tbody id='2Rv6v'></tbody>
                • 本文介绍了使用查询构建器删除 Doctrine 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个具有 OneToMany 关系的实体,ProjectServices.现在我想通过 project_id 删除所有服务.

                  I have two Entities with relation OneToMany, Project and Services. Now i want to remove all the services by project_id.

                  第一次尝试:

                  $qb = $em->createQueryBuilder();
                  $qb->delete('Services','s');
                  $qb->andWhere($qb->expr()->eq('s.project_id', ':id'));
                  $qb->setParameter(':id',$project->getId());
                  

                  此尝试失败,出现异常 Entity Service does not have property project_id.确实,该属性不存在,它只是在数据库表中作为外键.

                  This attempt fails with the Exception Entity Service does not have property project_id. And it's true, that property does not exists, it's only in database table as foreign key.

                  第二次尝试:

                  $qb = $em->createQueryBuilder();
                  $qb->delete('Services','s')->innerJoin('s.project','p');
                  $qb->andWhere($qb->expr()->eq('p.id', ':id'));
                  $qb->setParameter(':id',$project->getId());
                  

                  这个也会生成一个无效的 DQL 查询.

                  This one generetate a non valid DQL query too.

                  欢迎提供任何想法和示例.

                  Any ideas and examples will be welcome.

                  推荐答案

                  您使用的是 DQL,而不是 SQL,所以不要在您的条件中引用 ID,而是引用对象.

                  You're working with DQL, not SQL, so don't reference the IDs in your condition, reference the object instead.

                  因此您的第一个示例将更改为:

                  So your first example would be altered to:

                  $qb = $em->createQueryBuilder();
                  $qb->delete('Services', 's');
                  $qb->where('s.project = :project');
                  $qb->setParameter('project', $project);
                  

                  这篇关于使用查询构建器删除 Doctrine 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='t5uci'><style id='t5uci'><dir id='t5uci'><q id='t5uci'></q></dir></style></legend>

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

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

                            <tfoot id='t5uci'></tfoot>