Skip to content

Instantly share code, notes, and snippets.

@jeserkin
Last active December 16, 2015 04:19
Show Gist options
  • Save jeserkin/5376254 to your computer and use it in GitHub Desktop.
Save jeserkin/5376254 to your computer and use it in GitHub Desktop.
PHP Warning: Uncaught exception 'Doctrine\ORM\ORMException' with message 'Entity of type "A" has identity through a foreign entity "B", however this entity has no identity itself. You have to call EntityManager#persist() on the related entity and make sure that an identifier was generated before trying to persist "A". In case of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call EntityManager#flush() between both persist operations.' in /vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:50
<?php
//...
public function create()
{
/** @var $EntityManager \Doctrine\ORM\EntityManager */
$EntityManager = Context::getInstance()->get( 'db' )->getEntityManager();
/** @var $A */
$A = $EntityManager->find( 'A', $someId );
$B = new B();
$B
->setOne( $one )
->setTwo( $two )
->setA( $A );
$EntityManager->persist( $B );
/** @var $C */
$C = $EntityManager->find( 'C', $someOtherId );
$BtoC = new BC();
$BtoC
->setB( $B )
->setC( $C );
$EntityManager->persist( $BtoC );
$EntityManager->flush();
}
Stack trace:
#0 /vendor/doctrine/orm/lib/Doctrine/ORM/Id/AssignedGenerator.php(58): Doctrine\ORM\ORMException::entityMissingForeignAssignedId(Object(BC), Object(B))
#1 /vendor/doctrine/or in /home/sandbox/public_html/dev_ticket_system/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php on line 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment