From 0b3ae4b1699b0d688cbf50ab4ed0de0dd7197c5c Mon Sep 17 00:00:00 2001 From: romanb Date: Thu, 15 Oct 2009 19:03:27 +0000 Subject: [PATCH] [2.0] Removed all remaining references to deprecated allowPartialObjects option. --- lib/Doctrine/ORM/Configuration.php | 28 ------------------- .../ORM/Internal/Hydration/ObjectHydrator.php | 7 ++--- .../ORM/Mapping/AssociationMapping.php | 21 -------------- lib/Doctrine/ORM/Mapping/OneToOneMapping.php | 23 ++++++++++++++- .../Persisters/StandardEntityPersister.php | 7 +++++ lib/Doctrine/ORM/UnitOfWork.php | 12 +------- .../Functional/ClassTableInheritanceTest.php | 6 ---- ...ManyToManyBidirectionalAssociationTest.php | 2 -- ...nyToManySelfReferentialAssociationTest.php | 1 - ...anyToManyUnidirectionalAssociationTest.php | 1 - ...neToManySelfReferentialAssociationTest.php | 1 - .../OneToOneBidirectionalAssociationTest.php | 10 ++----- ...OneToOneSelfReferentialAssociationTest.php | 1 - .../OneToOneUnidirectionalAssociationTest.php | 1 - .../StandardEntityPersisterTest.php | 4 +-- .../ORM/Hydration/ObjectHydratorTest.php | 1 - .../ORM/Query/SelectSqlGenerationTest.php | 2 -- 17 files changed, 35 insertions(+), 93 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index b54e7d5d4..8c946b655 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -59,34 +59,6 @@ class Configuration extends \Doctrine\DBAL\Configuration $this->_attributes['metadataDriverImpl'] = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); } - /** - * Gets a boolean flag that indicates whether partial objects are allowed. - * - * If partial objects are allowed, Doctrine will never use proxies or lazy loading - * and you always only get what you explicitly query for. - * - * @return boolean Whether partial objects are allowed. - * @todo Remove - * @deprecated - */ - public function getAllowPartialObjects() - { - return true; - } - - /** - * Sets a boolean flag that specifies whether partial objects are allowed. - * - * If partial objects are allowed, Doctrine will never use proxies or lazy loading - * and you always only get what you explicitly query for. - * - * @param boolean $allowed Whether partial objects are allowed. - * @todo Remove - * @deprecated - */ - public function setAllowPartialObjects($allowed) - {} - /** * Sets the directory where Doctrine generates any necessary proxy class files. * diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 766663b52..8bb3d4fda 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -237,18 +237,15 @@ class ObjectHydrator extends AbstractHydrator private function _getEntityFromIdentityMap($className, array $data) { $class = $this->_ce[$className]; - if ($class->isIdentifierComposite) { $idHash = ''; foreach ($class->identifier as $fieldName) { $idHash .= $data[$fieldName] . ' '; } - $idHash = rtrim($idHash); + return $this->_uow->tryGetByIdHash(rtrim($idHash), $class->rootEntityName); } else { - $idHash = $data[$class->identifier[0]]; + return $this->_uow->tryGetByIdHash($data[$class->identifier[0]], $class->rootEntityName); } - - return $this->_uow->tryGetByIdHash($idHash, $class->rootEntityName); } /** diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index fd897462f..e44721c51 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -82,14 +82,6 @@ abstract class AssociationMapping */ public $isOwningSide = true; - /** - * Whether the association is optional (0..X) or not (1..X). - * By default all associations are optional. - * - * @var boolean - */ - public $isOptional = true; - /** * The name of the source Entity (the Entity that defines this mapping). * @@ -180,8 +172,6 @@ abstract class AssociationMapping } // Optional attributes for both sides - $this->isOptional = isset($mapping['optional']) ? - (bool)$mapping['optional'] : true; $this->fetchMode = isset($mapping['fetch']) ? $mapping['fetch'] : self::FETCH_LAZY; $this->cascades = isset($mapping['cascade']) ? @@ -288,17 +278,6 @@ abstract class AssociationMapping return ! $this->isOwningSide; } - /** - * Whether the association is optional (0..X), or not (1..X). - * - * @return boolean TRUE if the association is optional, FALSE otherwise. - * @todo Only applicable to OneToOne. Move there. - */ - public function isOptional() - { - return $this->isOptional; - } - /** * Gets the name of the source entity class. * diff --git a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php index f11196ea4..8b54d8071 100644 --- a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php +++ b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php @@ -59,6 +59,14 @@ class OneToOneMapping extends AssociationMapping * @var boolean */ public $orphanRemoval = false; + + /** + * Whether the association is optional (0..1) or not (1..1). + * By default all associations are optional. + * + * @var boolean + */ + public $isOptional = true; /** * The join column definitions. @@ -78,7 +86,7 @@ class OneToOneMapping extends AssociationMapping /** * Creates a new OneToOneMapping. * - * @param array $mapping The mapping info. + * @param array $mapping The mapping info. */ public function __construct(array $mapping) { @@ -117,6 +125,8 @@ class OneToOneMapping extends AssociationMapping $this->targetToSourceKeyColumns = array_flip($this->sourceToTargetKeyColumns); } + $this->isOptional = isset($mapping['optional']) ? + (bool)$mapping['optional'] : true; $this->orphanRemoval = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false; @@ -126,6 +136,17 @@ class OneToOneMapping extends AssociationMapping return $mapping; } + + /** + * Whether the association is optional (0..1), or not (1..1). + * + * @return boolean TRUE if the association is optional, FALSE otherwise. + * @todo Only applicable to OneToOne. Move there. + */ + public function isOptional() + { + return $this->isOptional; + } /** * Gets the join column definitions for this mapping. diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index 5225d3978..b9b454432 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -417,6 +417,13 @@ class StandardEntityPersister public function load(array $criteria, $entity = null, $assoc = null) { $stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria, $assoc)); + if (!is_object($stmt)) { + try { + throw new \Exception; + } catch (\Exception $e) { + var_dump($e->getTraceAsString()); + } + } $stmt->execute(array_values($criteria)); $result = $stmt->fetch(Connection::FETCH_ASSOC); $stmt->closeCursor(); diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c0b276f95..2afb51317 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1640,19 +1640,9 @@ class UnitOfWork implements PropertyChangedListener public function isCollectionScheduledForDeletion(PersistentCollection $coll) { - //... + return in_array($coll, $this->_collectionsDeletions, true); } - /*public function scheduleCollectionRecreation(PersistentCollection $coll) - { - $this->_collectionRecreations[] = $coll; - }*/ - - /*public function isCollectionScheduledForRecreation(PersistentCollection $coll) - { - //... - }*/ - /** * INTERNAL: * Creates an entity. Used for reconstitution of entities during hydration. diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 376e764c5..4c744ad92 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -43,7 +43,6 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.id asc"); $entities = $query->getResult(); @@ -56,7 +55,6 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('Roman S. Borschel', $entities[0]->getName()); $this->assertEquals('Guilherme Blanco', $entities[1]->getName()); $this->assertEquals(100000, $entities[1]->getSalary()); - $this->_em->getConfiguration()->setAllowPartialObjects(true); $this->_em->clear(); @@ -197,8 +195,6 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $orgId = $org->getId(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); - $q = $this->_em->createQuery('select a from Doctrine\Tests\Models\Company\CompanyOrganization a where a.id = ?1'); $q->setParameter(1, $orgId); @@ -219,7 +215,5 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($events[0] instanceof CompanyRaffle); $this->assertTrue($events[1] instanceof CompanyAuction); } - - $this->_em->getConfiguration()->setAllowPartialObjects(true); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php index 8e6bf8aaa..a4352ae51 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php @@ -85,7 +85,6 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati { $this->_createLoadingFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCategory'); $metadata->getAssociationMapping('products')->fetchMode = AssociationMapping::FETCH_LAZY; @@ -98,7 +97,6 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati { $this->_createLoadingFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); $metadata->getAssociationMapping('categories')->fetchMode = AssociationMapping::FETCH_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php index 6e43b2122..ac691d220 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php @@ -73,7 +73,6 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia { $this->_createLoadingFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); $metadata->getAssociationMapping('related')->fetchMode = AssociationMapping::FETCH_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php index a74aee5ca..6510f4f69 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php @@ -78,7 +78,6 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat public function testLazyLoadsCollection() { $this->_createFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); $metadata->getAssociationMapping('products')->fetchMode = AssociationMapping::FETCH_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index a9ba642ac..0fead683b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -89,7 +89,6 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio public function testLazyLoadsOneToManyAssociation() { $this->_createFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCategory'); $metadata->getAssociationMapping('children')->fetchMode = AssociationMapping::FETCH_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index 48145868d..ad44777d2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -67,7 +67,6 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional public function testLazyLoadsObjectsOnTheOwningSide() { $this->_createFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); $metadata->getAssociationMapping('customer')->fetchMode = AssociationMapping::FETCH_LAZY; @@ -82,7 +81,6 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional public function testLazyLoadsObjectsOnTheInverseSide() { $this->_createFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer'); $metadata->getAssociationMapping('mentor')->fetchMode = AssociationMapping::FETCH_EAGER; @@ -97,9 +95,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional } public function testUpdateWithProxyObject() - { - $this->_em->getConfiguration()->setAllowPartialObjects(false); - + { $cust = new ECommerceCustomer; $cust->setName('Roman'); $cart = new ECommerceCart; @@ -130,9 +126,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $cart3 = $query2->getSingleResult(); $this->assertTrue($cart3->getCustomer() instanceof ECommerceCustomer); - $this->assertEquals('Roman', $cart3->getCustomer()->getName()); - - $this->_em->getConfiguration()->setAllowPartialObjects(true); + $this->assertEquals('Roman', $cart3->getCustomer()->getName()); } protected function _createFixture() diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index 3e6c561cc..82b40e498 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -66,7 +66,6 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction { $this->_createFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer'); $metadata->getAssociationMapping('mentor')->fetchMode = AssociationMapping::FETCH_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index 83a14f3f0..4a3e61c25 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -61,7 +61,6 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testLazyLoadsObjects() { $this->_createFixture(); - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); $metadata->getAssociationMapping('shipping')->fetchMode = AssociationMapping::FETCH_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php index 8982b8ecf..9ed8f0821 100644 --- a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php @@ -24,9 +24,7 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase } public function testAcceptsForeignKeysAsCriteria() - { - $this->_em->getConfiguration()->setAllowPartialObjects(false); - + { $customer = new ECommerceCustomer(); $customer->setName('John Doe'); $cart = new ECommerceCart(); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index 794c62d43..477746137 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -132,7 +132,6 @@ class ObjectHydratorTest extends HydrationTestCase $this->_em->setProxyFactory($proxyFactory); // configuring lazy loading - $this->_em->getConfiguration()->setAllowPartialObjects(false); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); $metadata->getAssociationMapping('shipping')->fetchMode = AssociationMapping::FETCH_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index c6ae4fec6..6ca3c8bdb 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -303,7 +303,6 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase // "Get all persons who have $person as a friend." // Tough one: Many-many self-referencing ("friends") with class table inheritance - $this->_em->getConfiguration()->setAllowPartialObjects(false); $q3 = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p WHERE :param MEMBER OF p.friends'); $person = new \Doctrine\Tests\Models\Company\CompanyPerson; $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, 101); @@ -312,7 +311,6 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c2_.salary AS salary3, c2_.department AS department4, c0_.discr AS discr5, c0_.spouse_id AS spouse_id6 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id WHERE EXISTS (SELECT 1 FROM company_persons_friends c3_ INNER JOIN company_persons c4_ ON c3_.person_id = c0_.id WHERE c3_.friend_id = c4_.id AND c4_.id = ?)', $q3->getSql() ); - $this->_em->getConfiguration()->setAllowPartialObjects(true); } public function testSupportsCurrentDateFunction()