XF 2.0 Refresh Relation

Lukas W.

Well-known member
I'm creating a relation on demand if it does not already exist. However, if I then try to access it on a later point, it will still be null, so XF throws an error. Is there a way to refresh the entity to force XF to reload it?

Currently using this code:
PHP:
        /** @var \EventSystem\Entity\EventEntry $eventData */
        $eventData = $this->EventSystemData;

        if(!$eventData) {
            $eventData = $this->em()->create('EventSystem:EventEntry');
            $eventData->user_id = $this->user_id;
            $eventData->save();
        }
 
Last edited:
You probably want to use getRelationOrDefault which I think will do what you want, or alternatively use hydrateRelation passing in the newly created entity so it is available in the relation cache.
 
Back
Top Bottom