From c1edd5848f72ab5cb38c01708a9658c31d15ee24 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 2 Jan 2011 10:18:02 +0100 Subject: [PATCH] DDC-966 - Fix NOT NULL constraint SingleTableInheritance Generation using SchemaTool. --- lib/Doctrine/ORM/Tools/SchemaTool.php | 4 ++ .../ORM/Functional/SchemaTool/AllTests.php | 1 + .../SchemaTool/CompanySchemaTest.php | 53 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index e87a99a98..e88d28e5b 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -275,6 +275,10 @@ class SchemaTool $pkColumns = array(); foreach ($class->fieldMappings as $fieldName => $mapping) { + if ($class->isInheritanceTypeSingleTable() && isset($mapping['inherited'])) { + continue; + } + $column = $this->_gatherColumn($class, $mapping, $table); if ($class->isIdentifier($mapping['fieldName'])) { diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php index 646d8c07d..d9479b98a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php @@ -19,6 +19,7 @@ class AllTests { $suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Functional Tools'); + $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\CompanySchemaTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\MySqlSchemaToolTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\PostgreSqlSchemaToolTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\DDC214Test'); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php new file mode 100644 index 000000000..3a14056eb --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php @@ -0,0 +1,53 @@ +useModelSet('company'); + parent::setUp(); + } + + /** + * @group DDC-966 + * @return Schema + */ + public function testGeneratedSchema() + { + $schema = $this->_em->getConnection()->getSchemaManager()->createSchema(); + + $this->assertTrue($schema->hasTable('company_contracts')); + + return $schema; + } + + /** + * @group DDC-966 + * @depends testGeneratedSchema + */ + public function testSingleTableInheritance(Schema $schema) + { + $table = $schema->getTable('company_contracts'); + + // Check nullability constraints + $this->assertTrue($table->getColumn('id')->getNotnull()); + $this->assertTrue($table->getColumn('completed')->getNotnull()); + $this->assertFalse($table->getColumn('salesPerson_id')->getNotnull()); + $this->assertTrue($table->getColumn('discr')->getNotnull()); + $this->assertFalse($table->getColumn('fixPrice')->getNotnull()); + $this->assertFalse($table->getColumn('hoursWorked')->getNotnull()); + $this->assertFalse($table->getColumn('pricePerHour')->getNotnull()); + $this->assertFalse($table->getColumn('maxPrice')->getNotnull()); + } +} \ No newline at end of file