diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 59cb38aa3..04ec30aec 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -341,7 +341,7 @@ class PostgreSqlPlatform extends AbstractPlatform public function getListTableForeignKeysSql($table, $database = null) { - return "SELECT r.name, pg_catalog.pg_get_constraintdef(r.oid, true) as condef + return "SELECT r.conname, pg_catalog.pg_get_constraintdef(r.oid, true) as condef FROM pg_catalog.pg_constraint r WHERE r.conrelid = ( @@ -568,6 +568,7 @@ class PostgreSqlPlatform extends AbstractPlatform { return 'CREATE SEQUENCE ' . $sequence->getName() . ' INCREMENT BY ' . $sequence->getAllocationSize() . + ' MINVALUE ' . $sequence->getInitialValue() . ' START ' . $sequence->getInitialValue(); } diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index a36f811d5..3c3bbc68d 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -52,7 +52,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager } return new ForeignKeyConstraint( - $localColumns, $foreignTable, $foreignColumns, $tableForeignKey['name'], + $localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'], array('onUpdate' => $onUpdate, 'onDelete' => $onDelete) ); } @@ -87,7 +87,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager $this->_platform = $tmpPlatform; $this->_conn = $tmpConn; - } + } protected function _getPortableTriggerDefinition($trigger) { @@ -153,8 +153,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager protected function _getPortableSequenceDefinition($sequence) { - $data = $this->_conn->fetchAll('SELECT start_value, increment_by FROM '.$sequence['relname']); - return new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['start_value']); + $data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM '.$sequence['relname']); + return new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['min_value']); } protected function _getPortableTableConstraintDefinition($tableConstraint) diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 69341385f..d2be5fb1e 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -266,7 +266,7 @@ class ObjectHydrator extends AbstractHydrator continue; } - $parentClass = get_class($parentObject); + $parentClass = $this->_rsm->aliasMap[$parentAlias]; $oid = spl_object_hash($parentObject); $relationField = $this->_rsm->relationMap[$dqlAlias]; $relation = $this->_ce[$parentClass]->associationMappings[$relationField]; diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index 048092fff..197a14ac3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -145,7 +145,7 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase { $sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1); $this->assertEquals( - 'CREATE SEQUENCE myseq INCREMENT BY 20 START 1', + 'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1', $this->_platform->getCreateSequenceSql($sequence) ); $this->assertEquals( diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 92c4c7103..6f7292bb6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -19,7 +19,8 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ChildEntity'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity') + $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity'), + $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentRelatedEntity') )); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. @@ -56,7 +57,9 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertTrue(is_numeric($entities[1]->getId())); $this->assertTrue($entities[0] instanceof ParentEntity); - $this->assertTrue($entities[1] instanceof ChildEntity); + $this->assertTrue($entities[1] instanceof ChildEntity); + $this->assertNull($entities[0]->getParentRelated()); + $this->assertNull($entities[1]->getParentRelated()); $this->assertEquals('foobar', $entities[0]->getData()); $this->assertEquals('thedata', $entities[1]->getData()); $this->assertEquals(1234, $entities[1]->getNumber()); @@ -70,6 +73,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertEquals('thedata', $entities[0]->getData()); $this->assertEquals(1234, $entities[0]->getNumber()); + $this->assertNull($entities[0]->getParentRelated()); $this->_em->clear(); @@ -83,6 +87,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($entities[0]->getOwner() instanceof ChildEntity); $this->assertEquals('thedata', $entities[0]->getOwner()->getData()); $this->assertSame($entities[0], $entities[0]->getOwner()->getRelatedEntity()); + $this->assertNull($entities[0]->getOwner()->getParentRelated()); $query = $this->_em->createQuery("update Doctrine\Tests\ORM\Functional\ChildEntity e set e.data = 'newdata'"); @@ -114,6 +119,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1234, $child2->getNumber()); $this->assertEquals($child->getId(), $child2->getId()); $this->assertFalse($child === $child2); + $this->assertNull($child2->getParentRelated()); } public function testGetScalarResult() @@ -138,7 +144,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('child', $result[0]['e_discr']); } - public function testPolymorphicFind() + public function testPolymorphicFindAndQuery() { $child = new ChildEntity; $child->setData('thedata'); @@ -154,7 +160,33 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($child2 instanceof ChildEntity); $this->assertEquals('thedata', $child2->getData()); $this->assertSame(1234, $child2->getNumber()); + + $parentRelated = new ParentRelatedEntity; + $parentRelated->setData('related to parent!'); + $child2->setParentRelated($parentRelated); + $parentRelated->setParent($child2); + $this->_em->persist($parentRelated); + + //$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger); + + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery("select p, r from Doctrine\Tests\ORM\Functional\ParentEntity p join p.parentRelated r"); + $result = $query->getResult(); + + $this->assertEquals(1, count($result)); + $this->assertTrue($result[0] instanceof ChildEntity); + $related = $result[0]->getParentRelated(); + $this->assertFalse($related instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertTrue($related instanceof ParentRelatedEntity); + $this->assertEquals('related to parent!', $related->getData()); } + + /*public function testPolymorphicQueryWithJoin() + { + + }*/ } /** @@ -175,6 +207,9 @@ class ParentEntity { * @Column(name="DATA", type="string") */ private $data; + + /** @OneToOne(targetEntity="ParentRelatedEntity", mappedBy="parent") */ + private $parentRelated; public function getId() { return $this->id; @@ -187,6 +222,14 @@ class ParentEntity { public function setData($data) { $this->data = $data; } + + public function getParentRelated() { + return $this->parentRelated; + } + + public function setParentRelated($parentRelated) { + $this->parentRelated = $parentRelated; + } } /** @@ -263,3 +306,24 @@ class RelatedEntity { } } } + +/** @Entity */ +class ParentRelatedEntity { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + private $id; + public function getId() {return $this->id;} + /** @Column(type="string") */ + private $data; + public function getData() {return $this->data;} + public function setData($data) {$this->data = $data;} + /** + * @OneToOne(targetEntity="ParentEntity") + * @JoinColumn(name="parent_id", referencedColumnName="id") + */ + private $parent; + public function getParent() {return $this->parent;} + public function setParent($parent) {$this->parent = $parent;} +}