If you saw my previous question, this is kind of linked to it but a new question. So I have an Entity and I have a listener linked up to this. In my createAction I create my Object and then persist-flush it to my database. In my listener, I have set up a postFlush function
public function postFlush(PostFlushEventArgs $args)
{
$em = $args->getEntityManager();
foreach ($em->getUnitOfWork()->getScheduledEntityDeletions() as $entity) {
if ($entity instanceof AvailabilityAlert) {
var_dump("TEST");
$this->api_service->addFlightsAction($entity);
}
}
}
What I am trying to do in this function is get the entity that was just flushed. I have tried all the different actions of getUnitsOfWork e.g. getScheduledEntityDeletions but for none of them I can get into where the var_dump occurs.
How would I go about getting the flushed entity within this postFlush function?
To get just persisted to database entity you need not
postFlush
butpostPersist
:And don't forget to add next tag to your service:
According to Doctrine2 documentation here : http://doctrine-orm.readthedocs.org/en/latest/reference/events.html you can't call the flushed entities on
PostFlush
event.However you can split your logic : use the
OnFlush
event to get these entities and then pass it to thePostFlush
if the flush succeeded.