• <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 事件

        时间:2023-07-14
        • <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 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Doctrine:扩展实体类 下一篇:使用自定义 Doctrine 2 数据类型的依赖注入

                  相关文章

                  <tfoot id='x72uV'></tfoot>
                3. <legend id='x72uV'><style id='x72uV'><dir id='x72uV'><q id='x72uV'></q></dir></style></legend>
                    <bdo id='x72uV'></bdo><ul id='x72uV'></ul>
                4. <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>