[2.0][DDC-79][DDC-261] Fixed. Also fixed support for deleting objects by reference (getReference() + remove() + flush()) to effectively delete objects without loading them.
This commit is contained in:
parent
30f9403790
commit
ca23555c3e
@ -54,6 +54,13 @@ class ClassMetadata extends ClassMetadataInfo
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $reflFields = array();
|
public $reflFields = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prototype from which new instances of the mapped class are created.
|
||||||
|
*
|
||||||
|
* @var object
|
||||||
|
*/
|
||||||
|
private $_prototype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
|
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
|
||||||
@ -68,8 +75,6 @@ class ClassMetadata extends ClassMetadataInfo
|
|||||||
$this->namespace = $this->reflClass->getNamespaceName();
|
$this->namespace = $this->reflClass->getNamespaceName();
|
||||||
$this->primaryTable['name'] = $this->reflClass->getShortName();
|
$this->primaryTable['name'] = $this->reflClass->getShortName();
|
||||||
$this->rootEntityName = $entityName;
|
$this->rootEntityName = $entityName;
|
||||||
|
|
||||||
//$this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,7 +325,7 @@ class ClassMetadata extends ClassMetadataInfo
|
|||||||
public function __sleep()
|
public function __sleep()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'associationMappings', // unserialization bottleneck with many assocs
|
'associationMappings', // unserialization "bottleneck" with many associations
|
||||||
'changeTrackingPolicy',
|
'changeTrackingPolicy',
|
||||||
'columnNames', //TODO: Not really needed. Can use fieldMappings[$fieldName]['columnName']
|
'columnNames', //TODO: Not really needed. Can use fieldMappings[$fieldName]['columnName']
|
||||||
'customRepositoryClassName',
|
'customRepositoryClassName',
|
||||||
@ -375,13 +380,22 @@ class ClassMetadata extends ClassMetadataInfo
|
|||||||
} else {
|
} else {
|
||||||
$reflField = $this->reflClass->getProperty($field);
|
$reflField = $this->reflClass->getProperty($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
$reflField->setAccessible(true);
|
$reflField->setAccessible(true);
|
||||||
$this->reflFields[$field] = $reflField;
|
$this->reflFields[$field] = $reflField;
|
||||||
}
|
}
|
||||||
|
|
||||||
//$this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//public $prototype;
|
/**
|
||||||
|
* Creates a new instance of the mapped class, without invoking the constructor.
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
public function newInstance()
|
||||||
|
{
|
||||||
|
if ($this->_prototype === null) {
|
||||||
|
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
|
||||||
|
}
|
||||||
|
return clone $this->_prototype;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,7 +781,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
$hasListeners = $this->_evm->hasListeners(Events::postRemove);
|
$hasListeners = $this->_evm->hasListeners(Events::postRemove);
|
||||||
|
|
||||||
foreach ($this->_entityDeletions as $oid => $entity) {
|
foreach ($this->_entityDeletions as $oid => $entity) {
|
||||||
if (get_class($entity) == $className) {
|
if (get_class($entity) == $className || $entity instanceof Proxy && $entity instanceof $className) {
|
||||||
$persister->delete($entity);
|
$persister->delete($entity);
|
||||||
unset(
|
unset(
|
||||||
$this->_entityDeletions[$oid],
|
$this->_entityDeletions[$oid],
|
||||||
@ -956,11 +956,11 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
unset($this->_entityInsertions[$oid]);
|
unset($this->_entityInsertions[$oid]);
|
||||||
return; // entity has not been persisted yet, so nothing more to do.
|
return; // entity has not been persisted yet, so nothing more to do.
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $this->isInIdentityMap($entity)) {
|
if ( ! $this->isInIdentityMap($entity)) {
|
||||||
return; // ignore
|
return; // ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->removeFromIdentityMap($entity);
|
$this->removeFromIdentityMap($entity);
|
||||||
|
|
||||||
if (isset($this->_entityUpdates[$oid])) {
|
if (isset($this->_entityUpdates[$oid])) {
|
||||||
@ -1738,8 +1738,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
|
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//$entity = clone $class->prototype;
|
$entity = $class->newInstance();
|
||||||
$entity = new $className;
|
|
||||||
$oid = spl_object_hash($entity);
|
$oid = spl_object_hash($entity);
|
||||||
$this->_entityIdentifiers[$oid] = $id;
|
$this->_entityIdentifiers[$oid] = $id;
|
||||||
$this->_entityStates[$oid] = self::STATE_MANAGED;
|
$this->_entityStates[$oid] = self::STATE_MANAGED;
|
||||||
|
@ -116,4 +116,5 @@ class CmsUser
|
|||||||
$address->setUser($this);
|
$address->setUser($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -589,6 +589,29 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->_em->getConnection()->getConfiguration()->setSqlLogger($oldLogger);
|
$this->_em->getConnection()->getConfiguration()->setSqlLogger($oldLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRemoveEntityByReference()
|
||||||
|
{
|
||||||
|
$user = new CmsUser;
|
||||||
|
$user->name = 'Guilherme';
|
||||||
|
$user->username = 'gblanco';
|
||||||
|
$user->status = 'developer';
|
||||||
|
|
||||||
|
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$userRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->getId());
|
||||||
|
$this->_em->remove($userRef);
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users"));
|
||||||
|
|
||||||
|
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(null);
|
||||||
|
}
|
||||||
|
|
||||||
//DRAFT OF EXPECTED/DESIRED BEHAVIOR
|
//DRAFT OF EXPECTED/DESIRED BEHAVIOR
|
||||||
/*public function testPersistentCollectionContainsDoesNeverInitialize()
|
/*public function testPersistentCollectionContainsDoesNeverInitialize()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user