开发者

Doctrine 2 - How to get the ID of the last inserted id in PostPersist?

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 functio开发者_StackOverflown is in Mappedsuperclass, so it is available for each and every entity that extends Mappedsuperclass) Thanks.


...
public function postPersist(\Doctrine\ORM\Event\LifecycleEventArgs $e) {
    $newSeating = $e->getEntity();
    $id         = $newSeating->getId();
}
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜