Merge branch 'DDC-2106'
This commit is contained in:
commit
6c889eee64
@ -1848,16 +1848,7 @@ class BasicEntityPersister
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($this->em->getUnitOfWork()->getEntityState($value) === UnitOfWork::STATE_MANAGED) {
|
||||
$idValues = $this->em->getUnitOfWork()->getEntityIdentifier($value);
|
||||
|
||||
return reset($idValues);
|
||||
}
|
||||
|
||||
$class = $this->em->getClassMetadata(get_class($value));
|
||||
$idValues = $class->getIdentifierValues($value);
|
||||
|
||||
return reset($idValues);
|
||||
return $this->em->getUnitOfWork()->getSingleIdentifierValue($value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2860,7 +2860,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
throw ORMInvalidArgumentException::invalidCompositeIdentifier();
|
||||
}
|
||||
|
||||
$values = ($this->getEntityState($entity) === UnitOfWork::STATE_MANAGED)
|
||||
$values = $this->isInIdentityMap($entity)
|
||||
? $this->getEntityIdentifier($entity)
|
||||
: $class->getIdentifierValues($entity);
|
||||
|
||||
|
64
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php
Normal file
64
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Tests\Models\Generic\DateTimeModel;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
|
||||
/**
|
||||
* @group DDC-2106
|
||||
*/
|
||||
class DDC2106Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2106Entity'),
|
||||
));
|
||||
}
|
||||
|
||||
public function testDetachedEntityAsId()
|
||||
{
|
||||
// We want an uninitialized PersistentCollection $entity->children
|
||||
$entity = new DDC2106Entity();
|
||||
$this->_em->persist($entity);
|
||||
$this->_em->flush();
|
||||
$this->_em->detach($entity);
|
||||
$entity = $this->_em->getRepository(__NAMESPACE__ . '\DDC2106Entity')->findOneBy(array());
|
||||
|
||||
// ... and a managed entity without id
|
||||
$entityWithoutId = new DDC2106Entity();
|
||||
$this->_em->persist($entityWithoutId);
|
||||
|
||||
$criteria = Criteria::create()->where(Criteria::expr()->eq('parent', $entityWithoutId));
|
||||
$entity->children->matching($criteria)->count();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC2106Entity
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="IDENTITY")
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/** @ManyToOne(targetEntity="DDC2106Entity", inversedBy="children") */
|
||||
public $parent;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="DDC2106Entity", mappedBy="parent", cascade={"persist"})
|
||||
*/
|
||||
public $children;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->children = new \Doctrine\Common\Collections\ArrayCollection;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user