Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:10:42+00:00 2026-06-17T20:10:42+00:00

I currently have an entity which I would like to modify slightly upon load.

  • 0

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.

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).

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..

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:

  • Doesn’t load (allow access to) any associated data
  • Is only fired for owning Entities

I have no way of gently making these modifications.

Anyone have any advice, or experience on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:10:43+00:00Added an answer on June 17, 2026 at 8:10 pm

    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 \Doctrine\ORM\Event\LifecycleEventArgs $args
     */
    public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $args)
    {
        $this->em = $args->getEntityManager();
        $entity = $args->getEntity();
    
        if ($entity instanceof \Entities\Location)
        {
            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);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Entity in Code First Entity framework that currently looks like this:
I have one entity which is mapped to a db schema currently. I am
I have a Person entity which belongs to a Department in a one to
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
I currently have the following MySQL statement to replace the HTML entity for a
Currently have password protection on my main and sub directories, however I'd like to
I currently have a table of concentrations, which are linked to a table of
I currently have one project that currently contains multiple packages. These packages make up
I have a news table and I would like to implement custom ordering. I
I'm currently making a C++ game. I have my main loop during which the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.