Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0-ALPHA4
-
Fix Version/s: 2.0-BETA1
-
Component/s: None
-
Security Level: All
-
Labels:None
Description
Introduction:
I have a Product, which has many (OneToMany collection) Pictures. Picture has a File (ManyToOne with cascade=
).
The problem:
When I remove a picture from a product
$product->pictures->removeElement($picture); $picture->resetProduct();
doctrine removes picture, then cascade removes file, but file is not yet initialized. Doctrine tries to check entity state:
public function getEntityState($entity, $assume = null)
{
$oid = spl_object_hash($entity);
if ( ! isset($this->_entityStates[$oid])) {
...
if ($assume === null) {
if ($this->_em->getClassMetadata(get_class($entity))->getIdentifierValues($entity)) {
$this->_entityStates[$oid] = self::STATE_DETACHED;
...
The getIdentifierValues method tries to take entity id through reflection, but id field is absent.
I think that the getEntityState method should support case when entity is instance of IProxy...
May be I'm wrong, but as workaround I made the following:
1. Added a _load method to Proxy interface (why it is not called IProxy?)
2. Made the _load method public (in ProxyFactory)
3. Added another one case to getEntityState method:
if ($entity instanceof \Doctrine\ORM\Proxy\Proxy) { $entity->_load(); } elseif ($assume === null) {