I face exception when I'm trying to remove entity with the help of Doctrine.
Here is my code:
if ($id > 0) {
$phase = $em->find("Phase", $id);
if ($phase instanceof Phase) {
$picture = $phase->getPicture();
if ($picture != "")
deleteFile($dir . getPhotoSrc($picture));
$logo = $phase->getLogo();
if ($picture != "")
deleteFile($dir . getPhotoSrc($logo));
$logo2 = $phase->getLogo2();
if ($picture != "")
deleteFile($dir . getPhotoSrc($logo2));
$em->remove($phase);
$em->flush();
}
}
This is the error I'm getting
Entity was not found.
#0 /home/www/html/v3/admin/proxies/__CG__Phase.php(108): Doctrine\ORM\Proxy\ProxyFactory->Doctrine\ORM\Proxy\{closure}(Object(Proxies\__CG__\Phase), '__load', Array)
#1 /home/www/html/v3/admin/proxies/__CG__Phase.php(108): Closure->__invoke(Object(Proxies\__CG__\Phase), '__load', Array)
#2 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2268): Proxies\__CG__\Phase->__load()
#3 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Proxies\__CG__\Phase), Array)
#4 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Proxies\__CG__\Phase), Array)
#5 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Proxies\__CG__\Plan), Array)
#6 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Proxies\__CG__\Plan), Array)
#7 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Proxies\__CG__\Phase), Array)
#8 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Proxies\__CG__\Phase), Array)
#9 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Plan), Array)
#10 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Plan), Array)
#11 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Phase), Array)
#12 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1663): Doctrine\ORM\UnitOfWork->doRemove(Object(Phase), Array)
#13 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(647): Doctrine\ORM\UnitOfWork->remove(Object(Phase))
#14 /home/www/html/v3/admin/project_action.php(218): Doctrine\ORM\EntityManager->remove(Object(Phase))
#15 {main}
In class Plan I have:
/**
* @ManyToMany(targetEntity="Phase", inversedBy="plans", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
* @JoinTable(name="links_plan_phase",
* joinColumns={@JoinColumn(name="plan_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="phase_id", referencedColumnName="id")}
* )
**/
protected $phases;
In class Phase I have:
/**
* @ManyToMany(targetEntity="Plan", mappedBy="phases", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
**/
private $plans;
I'm finally confused. Can anybody help me to find where is the problem and how ca I solve it.