1
0
mirror of synced 2024-12-13 06:46:03 +03:00

[2.0][DDC-187] Fixed. Also fixed some DBAL failures on postgres.

This commit is contained in:
romanb 2009-12-03 13:17:56 +00:00
parent 73017b536f
commit 15f84f6eb0
5 changed files with 75 additions and 10 deletions

View File

@ -341,7 +341,7 @@ class PostgreSqlPlatform extends AbstractPlatform
public function getListTableForeignKeysSql($table, $database = null) 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 FROM pg_catalog.pg_constraint r
WHERE r.conrelid = WHERE r.conrelid =
( (
@ -568,6 +568,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return 'CREATE SEQUENCE ' . $sequence->getName() . return 'CREATE SEQUENCE ' . $sequence->getName() .
' INCREMENT BY ' . $sequence->getAllocationSize() . ' INCREMENT BY ' . $sequence->getAllocationSize() .
' MINVALUE ' . $sequence->getInitialValue() .
' START ' . $sequence->getInitialValue(); ' START ' . $sequence->getInitialValue();
} }

View File

@ -52,7 +52,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
} }
return new ForeignKeyConstraint( return new ForeignKeyConstraint(
$localColumns, $foreignTable, $foreignColumns, $tableForeignKey['name'], $localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'],
array('onUpdate' => $onUpdate, 'onDelete' => $onDelete) array('onUpdate' => $onUpdate, 'onDelete' => $onDelete)
); );
} }
@ -153,8 +153,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition($sequence)
{ {
$data = $this->_conn->fetchAll('SELECT start_value, increment_by FROM '.$sequence['relname']); $data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM '.$sequence['relname']);
return new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['start_value']); return new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['min_value']);
} }
protected function _getPortableTableConstraintDefinition($tableConstraint) protected function _getPortableTableConstraintDefinition($tableConstraint)

View File

@ -266,7 +266,7 @@ class ObjectHydrator extends AbstractHydrator
continue; continue;
} }
$parentClass = get_class($parentObject); $parentClass = $this->_rsm->aliasMap[$parentAlias];
$oid = spl_object_hash($parentObject); $oid = spl_object_hash($parentObject);
$relationField = $this->_rsm->relationMap[$dqlAlias]; $relationField = $this->_rsm->relationMap[$dqlAlias];
$relation = $this->_ce[$parentClass]->associationMappings[$relationField]; $relation = $this->_ce[$parentClass]->associationMappings[$relationField];

View File

@ -145,7 +145,7 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
{ {
$sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1); $sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1);
$this->assertEquals( $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->_platform->getCreateSequenceSql($sequence)
); );
$this->assertEquals( $this->assertEquals(

View File

@ -19,7 +19,8 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_schemaTool->createSchema(array( $this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ChildEntity'), $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) { } catch (\Exception $e) {
// Swallow all exceptions. We do not test the schema tool here. // Swallow all exceptions. We do not test the schema tool here.
@ -57,6 +58,8 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertTrue(is_numeric($entities[1]->getId())); $this->assertTrue(is_numeric($entities[1]->getId()));
$this->assertTrue($entities[0] instanceof ParentEntity); $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('foobar', $entities[0]->getData());
$this->assertEquals('thedata', $entities[1]->getData()); $this->assertEquals('thedata', $entities[1]->getData());
$this->assertEquals(1234, $entities[1]->getNumber()); $this->assertEquals(1234, $entities[1]->getNumber());
@ -70,6 +73,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertTrue(is_numeric($entities[0]->getId())); $this->assertTrue(is_numeric($entities[0]->getId()));
$this->assertEquals('thedata', $entities[0]->getData()); $this->assertEquals('thedata', $entities[0]->getData());
$this->assertEquals(1234, $entities[0]->getNumber()); $this->assertEquals(1234, $entities[0]->getNumber());
$this->assertNull($entities[0]->getParentRelated());
$this->_em->clear(); $this->_em->clear();
@ -83,6 +87,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertTrue($entities[0]->getOwner() instanceof ChildEntity); $this->assertTrue($entities[0]->getOwner() instanceof ChildEntity);
$this->assertEquals('thedata', $entities[0]->getOwner()->getData()); $this->assertEquals('thedata', $entities[0]->getOwner()->getData());
$this->assertSame($entities[0], $entities[0]->getOwner()->getRelatedEntity()); $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'"); $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(1234, $child2->getNumber());
$this->assertEquals($child->getId(), $child2->getId()); $this->assertEquals($child->getId(), $child2->getId());
$this->assertFalse($child === $child2); $this->assertFalse($child === $child2);
$this->assertNull($child2->getParentRelated());
} }
public function testGetScalarResult() public function testGetScalarResult()
@ -138,7 +144,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals('child', $result[0]['e_discr']); $this->assertEquals('child', $result[0]['e_discr']);
} }
public function testPolymorphicFind() public function testPolymorphicFindAndQuery()
{ {
$child = new ChildEntity; $child = new ChildEntity;
$child->setData('thedata'); $child->setData('thedata');
@ -154,7 +160,33 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertTrue($child2 instanceof ChildEntity); $this->assertTrue($child2 instanceof ChildEntity);
$this->assertEquals('thedata', $child2->getData()); $this->assertEquals('thedata', $child2->getData());
$this->assertSame(1234, $child2->getNumber()); $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()
{
}*/
} }
/** /**
@ -176,6 +208,9 @@ class ParentEntity {
*/ */
private $data; private $data;
/** @OneToOne(targetEntity="ParentRelatedEntity", mappedBy="parent") */
private $parentRelated;
public function getId() { public function getId() {
return $this->id; return $this->id;
} }
@ -187,6 +222,14 @@ class ParentEntity {
public function setData($data) { public function setData($data) {
$this->data = $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;}
}