Get the last insert id with doctrine 2?

tom picture tom · Aug 18, 2010 · Viewed 100.8k times · Source

How can I get the last insert id with doctrine 2 ORM? I didn't find this in the documentation of doctrine, is this even possible?

Answer

tom picture tom · Aug 18, 2010

I had to use this after the flush to get the last insert id:

$em->persist($user);
$em->flush();
$user->getId();