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

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

        <bdo id='szkXQ'></bdo><ul id='szkXQ'></ul>
      <legend id='szkXQ'><style id='szkXQ'><dir id='szkXQ'><q id='szkXQ'></q></dir></style></legend>

      1. Doctrine 2 DQL - 选择多对多字段为空的行?

        时间:2024-08-10
        <i id='8Xt1p'><tr id='8Xt1p'><dt id='8Xt1p'><q id='8Xt1p'><span id='8Xt1p'><b id='8Xt1p'><form id='8Xt1p'><ins id='8Xt1p'></ins><ul id='8Xt1p'></ul><sub id='8Xt1p'></sub></form><legend id='8Xt1p'></legend><bdo id='8Xt1p'><pre id='8Xt1p'><center id='8Xt1p'></center></pre></bdo></b><th id='8Xt1p'></th></span></q></dt></tr></i><div id='8Xt1p'><tfoot id='8Xt1p'></tfoot><dl id='8Xt1p'><fieldset id='8Xt1p'></fieldset></dl></div>

      2. <tfoot id='8Xt1p'></tfoot>

          <tbody id='8Xt1p'></tbody>
        <legend id='8Xt1p'><style id='8Xt1p'><dir id='8Xt1p'><q id='8Xt1p'></q></dir></style></legend>

        • <small id='8Xt1p'></small><noframes id='8Xt1p'>

                  <bdo id='8Xt1p'></bdo><ul id='8Xt1p'></ul>
                  本文介绍了Doctrine 2 DQL - 选择多对多字段为空的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在这个例子中我有两个类 - DeliveryMethod 和 Country.它们之间是多对多的关系.

                  I have two classes in this example - DeliveryMethod and Country. They have a many-to-many relationship with each other.

                  我想要做的是选择没有任何国家映射到它们的所有 DeliveryMethods.

                  What I want to do is select all DeliveryMethods that do not have any Countries mapped to them.

                  我可以做相反的事情,即选择至少有一个国家的所有交付方式 -

                  I can do the opposite, that is select all delivery methods that have at least one country -

                  SELECT m FROM DeliveryMethod m JOIN m.countries
                  

                  但我不知道如何选择国家字段为空的位置.在普通 SQL 中,我会执行以下操作(deliverymethod_country 是链接表):

                  But I can't figure out how to do select where the countries field is empty. In plain SQL I would do the following (deliverymethod_country is the linking table):

                  SELECT m.* FROM deliverymethods m
                  LEFT JOIN deliverymethod_country dc ON dc.deliverymethod_id = m.id
                  WHERE dc.deliverymethod_id IS NULL
                  

                  但是任何与此等效的 DQL 都不起作用,例如:

                  However any DQL equivalent of this doesn't work, for example:

                  SELECT m FROM DeliveryMethod m LEFT JOIN m.countries WHERE m.countries IS NULL
                  

                  这给了我这个错误:

                  [Syntax Error] line 0, col 75: Error: Expected end of string, got 'm'
                  

                  推荐答案

                  这个呢?假设 $qb 是您的查询构建器实例

                  What about this? Assuming $qb is your query builder instance

                  $qb->select('m')
                     ->from('DeliveryMethods','m')
                     ->leftJoin('m.countries','c')
                     ->having('COUNT(c.id) = 0')
                     ->groupBy('m.id');
                  

                  这将为您提供与国家/地区关联的 DeliveryMethods,关联国家/地区的数量为 0

                  This would give you the DeliveryMethods which is associated with countries and count of the associated countries is 0

                  这篇关于Doctrine 2 DQL - 选择多对多字段为空的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:原则 2:使用查询生成器更新查询 下一篇:在教义中使用列值作为数组索引

                  相关文章

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

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

                    <tfoot id='LmWUo'></tfoot>