<tfoot id='n368Q'></tfoot>

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

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

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

      • <bdo id='n368Q'></bdo><ul id='n368Q'></ul>
    1. 如何在没有 Doctrine 关系的情况下加入?

      How to JOIN without a relationship in Doctrine?(如何在没有 Doctrine 关系的情况下加入?)

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

      <small id='01vPz'></small><noframes id='01vPz'>

      <tfoot id='01vPz'></tfoot>

        <tbody id='01vPz'></tbody>

      • <bdo id='01vPz'></bdo><ul id='01vPz'></ul>
          • <legend id='01vPz'><style id='01vPz'><dir id='01vPz'><q id='01vPz'></q></dir></style></legend>
              1. 本文介绍了如何在没有 Doctrine 关系的情况下加入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个实体Log(表log),成员resourceTyperesourceId(列>resource_logresource_id).resourceType 可以例如Order(用于订单操作,例如状态更改)或 Whatever(用于 Whatever 相关操作).Log 和资源"实体/表之间没有关系(无论是在 Doctrine 中,还是在数据库中).

                I have an entity Log (table log) with members resourceType and resourceId (with columns resource_log and resource_id). The resourceType can e.g. Order (for actions on orders, e.g. status changes ) or Whatever (for Whatever related actions). There is no relationships (neither in Doctrine, nor in the database) between the Log and the "resource" entities/tables.

                现在我只想选择与 Order 相关的 LogmyOrderProperty = "someValue".这意味着:

                Now I want to select only the Logs, that are related to Orders with myOrderProperty = "someValue". That means:

                SELECT
                    *
                FROM
                    `log`
                JOIN
                    `order` ON `order`.`id` = `log`.`resource_id` AND `log`.`resource_type` = 'order'
                WHERE
                    `order`.`my_order_property` LIKE '%my_order_property_value%'
                

                但是代码

                $queryBuilder = $this->entityManager->createQueryBuilder();
                $queryBuilder->select('l')->from(Log::class, 'l');
                $queryBuilder->join('l.order', 'o');
                ...
                $queryBuilder
                    ->where('o.myOrderProperty = :myOrderProperty')
                    ->setParameter('myOrderProperty', $myOrderProperty);
                

                不起作用,因为实体 LogOrder 没有任何关系(尽管它有一个属性 order):

                doesn't work, since the entity Log doesn't have any relationship with the Order (though it has a property order):

                [Semantical Error] line 0, col 102 near 'o WHERE o.myOrderProperty': Error: Class MyNamespaceLog has no association named order
                

                如何在两个实体之间没有定义关系的情况下JOIN?

                我知道,我可以使用 继承.但从语义上讲,它不是继承的情况.那么有没有其他办法解决这个问题?

                I know, I could use inheritance. But semantically it's not an inheritance case. So is there another way for solving the problem?

                推荐答案

                没有关系的JOIN可以这样实现:

                The JOIN without relationship can be implemented like this:

                $queryBuilder = $this->entityManager->createQueryBuilder();
                $queryBuilder->select('l')->from(Log::class, 'l');
                $queryBuilder->join(
                    Order::class,
                    'o',
                    DoctrineORMQueryExprJoin::WITH,
                    'o.id = l.resourceId'
                );
                ...
                $queryBuilder
                    ->where('o.myOrderProperty = :myOrderProperty')
                    ->setParameter('myOrderProperty', $myOrderProperty);
                

                唯一的问题是,加入的实体没有添加到主实体中,因此 $myLog->getOrder(...) 返回 null.

                The only problem is, that the joined entities are not added to the main entity, so that $myLog->getOrder(...) returns null.

                这篇关于如何在没有 Doctrine 关系的情况下加入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <legend id='JaxnM'><style id='JaxnM'><dir id='JaxnM'><q id='JaxnM'></q></dir></style></legend>

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

                      <tbody id='JaxnM'></tbody>
                      <tfoot id='JaxnM'></tfoot>
                      1. <small id='JaxnM'></small><noframes id='JaxnM'>

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