1
0
mirror of synced 2025-01-22 08:11:40 +03:00

[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:
romanb 2010-02-10 10:47:42 +00:00
parent 30f9403790
commit ca23555c3e
4 changed files with 49 additions and 12 deletions

View File

@ -55,6 +55,13 @@ class ClassMetadata extends ClassMetadataInfo
*/
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
* metadata of the class with the given name.
@ -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',
@ -379,9 +384,18 @@ class ClassMetadata extends ClassMetadataInfo
$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;
}
}

View File

@ -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],
@ -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;

View File

@ -116,4 +116,5 @@ class CmsUser
$address->setUser($this);
}
}
}

View File

@ -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()
{