[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
|
||||
*/
|
||||
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
|
||||
@ -68,8 +75,6 @@ class ClassMetadata extends ClassMetadataInfo
|
||||
$this->namespace = $this->reflClass->getNamespaceName();
|
||||
$this->primaryTable['name'] = $this->reflClass->getShortName();
|
||||
$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()
|
||||
{
|
||||
return array(
|
||||
'associationMappings', // unserialization bottleneck with many assocs
|
||||
'associationMappings', // unserialization "bottleneck" with many associations
|
||||
'changeTrackingPolicy',
|
||||
'columnNames', //TODO: Not really needed. Can use fieldMappings[$fieldName]['columnName']
|
||||
'customRepositoryClassName',
|
||||
@ -375,13 +380,22 @@ class ClassMetadata extends ClassMetadataInfo
|
||||
} else {
|
||||
$reflField = $this->reflClass->getProperty($field);
|
||||
}
|
||||
|
||||
|
||||
$reflField->setAccessible(true);
|
||||
$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);
|
||||
|
||||
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);
|
||||
unset(
|
||||
$this->_entityDeletions[$oid],
|
||||
@ -956,11 +956,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
unset($this->_entityInsertions[$oid]);
|
||||
return; // entity has not been persisted yet, so nothing more to do.
|
||||
}
|
||||
|
||||
|
||||
if ( ! $this->isInIdentityMap($entity)) {
|
||||
return; // ignore
|
||||
}
|
||||
|
||||
|
||||
$this->removeFromIdentityMap($entity);
|
||||
|
||||
if (isset($this->_entityUpdates[$oid])) {
|
||||
@ -1738,8 +1738,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
|
||||
}
|
||||
} else {
|
||||
//$entity = clone $class->prototype;
|
||||
$entity = new $className;
|
||||
$entity = $class->newInstance();
|
||||
$oid = spl_object_hash($entity);
|
||||
$this->_entityIdentifiers[$oid] = $id;
|
||||
$this->_entityStates[$oid] = self::STATE_MANAGED;
|
||||
|
@ -116,4 +116,5 @@ class CmsUser
|
||||
$address->setUser($this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -589,6 +589,29 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$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
|
||||
/*public function testPersistentCollectionContainsDoesNeverInitialize()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user