I am getting an odd bug when I am removing an entity using the entity manager. An exception is being thrown saying "A new entity was found through a relationship that was not configured to cascade persist operations" but I have no new entities. I think this may be a bug in Doctrine but figured I would ask around a bit first to make sure that I wasn't doing anything wrong before filling a report.
The relevant code:
<?php
$em = Doctrine\ORM\EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), $config);
$qb = $em
->getRepository('Bar')
->createQueryBuilder('bar1')
->select('bar1, foo1, bar2')
->join('bar1.foo', 'foo1')
->join('foo1.bar', 'bar2')
;
$qb->getQuery()->getResult();
$bar = $em->getRepository('Bar')->findOneBy(array('id' => 20));
$em->transactional(function($em) use ($bar) {
$em->remove($bar);
$em->flush();
});
If I remove the $em->transactional
that wraps the remove and flush operation the remove works. Also, if I remove $qb->getQuery()->getResult();
for the previous query the remove and flush call works.
The error I am getting is:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'A new entity was found through a relationship that was not configured to cascade persist operations: Bar@0000000049dcca970000000025d8d6f9. Explicitly persist the new entity or configure cascading persist operations on the relationship.' in doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php:576 Stack trace: #0 doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php(495): Doctrine\ORM\UnitOfWork >computeAssociationChanges(Array, Object(Doctrine\ORM\PersistentCollection)) #1 doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php(537): Doctrine\ORM\UnitOfWork->computeChangeSet(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(Foo)) #2 doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php(256): Doctrine\ORM\UnitOfWork->computeChangeSets() #3 doctrine2-orm/lib/Doctrine/ORM/EntityManager.php(334): Doctrine\ORM\UnitO in doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php on line 576
A complete working example can be found in this gist.