• <legend id='2EN9e'><style id='2EN9e'><dir id='2EN9e'><q id='2EN9e'></q></dir></style></legend>
  • <small id='2EN9e'></small><noframes id='2EN9e'>

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

      1. 关联的学说 postLoad 事件

        Doctrine postLoad event for associations(关联的学说 postLoad 事件)
        • <tfoot id='bNQSw'></tfoot>
          • <small id='bNQSw'></small><noframes id='bNQSw'>

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

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

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

                2. 本文介绍了关联的学说 postLoad 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前有一个实体,我想在加载时稍微修改它.此修改将是一次性更改,然后将与实体一起保存在新字段中.

                  I currently have an entity which I would like to modify slightly upon load. This modification will be a one time change which will then be persisted in a new field along with the entity.

                  澄清我当前的目标:实体是一个位置"并且构成嵌套集的一部分.它有一个名称、lft/rgt 值和一个 Id.我使用这个实体执行的一项计算成本很高的任务是获取完整的位置路径并将其显示为文本.例如,对于位置实体滑铁卢",我想显示为滑铁卢|伦敦|英国".这涉及遍历整个集合(到根节点).

                  To clarify my current objective: The entity is a "Location" and forms part of a nested set. It has a name, lft/rgt values and an Id. One computationally expensive task I was performing with this entity was to fetch a full location path and display it as text. For example, with the location entity "Waterloo" I want to display as "Waterloo|London|United Kingdom". This involves traversing through the entire set (to the root node).

                  为了降低成本,我在 Location 实体上创建了一个新字段,该字段可以使用此值进行标记(并在修改位置(或树中的任何位置)名称时进行更新).考虑到我的应用程序处于活动状态,我需要避免将其作为一次性进程运行,因为它会在数据库上产生相当密集的一次性命中,相反,我想在每个位置(没有该值)已加载.我认为 Doctrine 的 postLoad 事件机制非常适合实现这一目标,但是..

                  To reduce the cost of this I've created a new field on the Location entity that can be stamped with this value (and updated as/when the location (or any location within the tree) name is modified). Considering my application is in a live state I need to avoid running this as a one off process as it would incur quite an intensive one-time hit on the DB, instead I'd like to apply this update as and when each location (without that value) is loaded. I assumed Doctrine's postLoad event mechanism would be perfect for achieving this, however..

                  位置实体不是由我的应用程序直接加载的,它们将始终是关系的反面.有了这个想法,以及学说的 postLoad 事件的事实:

                  The Location entities are not loaded directly by my application, they will always be the inverse side of a relation. With this is mind, and the fact that doctrine's postLoad event:

                  • 不加载(允许访问)任何相关数据
                  • 仅因拥有实体而被解雇

                  我无法温和地进行这些修改.

                  I have no way of gently making these modifications.

                  有人对此有任何建议或经验吗?

                  Anyone have any advice, or experience on this?

                  推荐答案

                  通过使用实体管理器上的 initializeObject() 方法,我能够在 postLoad 事件中加载关联的 Location 对象.

                  I was able to load the associated Location objects within the postLoad event by using the initializeObject() method on the Entity Manager.

                  /**
                   * Upon loading the object, if the location text isn't set, set it
                   * @param DoctrineORMEventLifecycleEventArgs $args
                   */
                  public function postLoad(DoctrineORMEventLifecycleEventArgs $args)
                  {
                      $this->em = $args->getEntityManager();
                      $entity = $args->getEntity();
                  
                      if ($entity instanceof EntitiesLocation)
                      {
                          if (is_null($entity->getPathText()))
                          {
                              $entity->setPathText("new value");
                              $this->em->flush($entity);
                          }
                      } elseif ($entity instanceof {parent Entity})
                      {
                          $location = $entity->getLocation();
                          // This triggers the postLoad event again, but this time with Location as the parent Entity
                          $this->em->initializeObject($location);
                      }
                  }
                  

                  这篇关于关联的学说 postLoad 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                  <tfoot id='x72uV'></tfoot>
                  • <legend id='x72uV'><style id='x72uV'><dir id='x72uV'><q id='x72uV'></q></dir></style></legend>
                      <tbody id='x72uV'></tbody>
                      <bdo id='x72uV'></bdo><ul id='x72uV'></ul>
                      • <small id='x72uV'></small><noframes id='x72uV'>

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