Reputation: 475
Title explains it all. I have a lifecyclecallback function in entity. I want to get last inserted id from PostPersist event not from the entity. AS an example I dont want to do
$newSeating = new Seat();
$newSeating->setTitle("Something");
$this->_em->persist($newSeating);
$this->_em->flush();
$newSeating->getId();
In documentation it is written
postPersist - The postPersist event occurs for an entity after the entity has been made persistent. It will be invoked after the database insert operations. Generated primary key values are available in the postPersist event.
So how can I get the primary key value in postPersist? (I"m using Mappedsuperclass and postpersist function is in Mappedsuperclass, so it is available for each and every entity that extends Mappedsuperclass) Thanks.
Upvotes: 2
Views: 4083
Reputation: 83672
...
public function postPersist(\Doctrine\ORM\Event\LifecycleEventArgs $e) {
$newSeating = $e->getEntity();
$id = $newSeating->getId();
}
...
Upvotes: 4