[DDC-2387] Fix DatabaseDriver not working with combinations of composite/association keys.
This commit is contained in:
parent
86277def7e
commit
7220c3c125
@ -224,7 +224,8 @@ class DatabaseDriver implements MappingDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($ids) {
|
if ($ids) {
|
||||||
if (count($ids) == 1) {
|
// We need to check for the columns here, because we might have associations as id as well.
|
||||||
|
if (count($primaryKeyColumns) == 1) {
|
||||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,9 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Functional;
|
namespace Doctrine\Tests\ORM\Functional;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../TestInit.php';
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
class DatabaseDriverTest extends DatabaseDriverTestCase
|
||||||
Doctrine\Common\Util\Inflector;
|
|
||||||
|
|
||||||
class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
|
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
|
||||||
@ -148,44 +145,4 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
$this->assertEquals(0, count($metadatas['DbdriverBaz']->associationMappings), "no association mappings should be detected.");
|
$this->assertEquals(0, count($metadatas['DbdriverBaz']->associationMappings), "no association mappings should be detected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function convertToClassMetadata(array $entityTables, array $manyTables = array())
|
|
||||||
{
|
|
||||||
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm);
|
|
||||||
$driver->setTables($entityTables, $manyTables);
|
|
||||||
|
|
||||||
$metadatas = array();
|
|
||||||
foreach ($driver->getAllClassNames() AS $className) {
|
|
||||||
$class = new ClassMetadataInfo($className);
|
|
||||||
$driver->loadMetadataForClass($className, $class);
|
|
||||||
$metadatas[$className] = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $metadatas;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $className
|
|
||||||
* @return ClassMetadata
|
|
||||||
*/
|
|
||||||
protected function extractClassMetadata(array $classNames)
|
|
||||||
{
|
|
||||||
$classNames = array_map('strtolower', $classNames);
|
|
||||||
$metadatas = array();
|
|
||||||
|
|
||||||
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm);
|
|
||||||
foreach ($driver->getAllClassNames() as $className) {
|
|
||||||
if (!in_array(strtolower($className), $classNames)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$class = new ClassMetadataInfo($className);
|
|
||||||
$driver->loadMetadataForClass($className, $class);
|
|
||||||
$metadatas[$className] = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($metadatas) != count($classNames)) {
|
|
||||||
$this->fail("Have not found all classes matching the names '" . implode(", ", $classNames) . "' only tables " . implode(", ", array_keys($metadatas)));
|
|
||||||
}
|
|
||||||
return $metadatas;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional;
|
||||||
|
|
||||||
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common BaseClass for DatabaseDriver Tests
|
||||||
|
*/
|
||||||
|
abstract class DatabaseDriverTestCase extends OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function convertToClassMetadata(array $entityTables, array $manyTables = array())
|
||||||
|
{
|
||||||
|
$sm = $this->_em->getConnection()->getSchemaManager();
|
||||||
|
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($sm);
|
||||||
|
$driver->setTables($entityTables, $manyTables);
|
||||||
|
|
||||||
|
$metadatas = array();
|
||||||
|
foreach ($driver->getAllClassNames() AS $className) {
|
||||||
|
$class = new ClassMetadataInfo($className);
|
||||||
|
$driver->loadMetadataForClass($className, $class);
|
||||||
|
$metadatas[$className] = $class;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $metadatas;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @return ClassMetadata
|
||||||
|
*/
|
||||||
|
protected function extractClassMetadata(array $classNames)
|
||||||
|
{
|
||||||
|
$classNames = array_map('strtolower', $classNames);
|
||||||
|
$metadatas = array();
|
||||||
|
|
||||||
|
$sm = $this->_em->getConnection()->getSchemaManager();
|
||||||
|
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($sm);
|
||||||
|
|
||||||
|
foreach ($driver->getAllClassNames() as $className) {
|
||||||
|
if (!in_array(strtolower($className), $classNames)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$class = new ClassMetadataInfo($className);
|
||||||
|
$driver->loadMetadataForClass($className, $class);
|
||||||
|
$metadatas[$className] = $class;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($metadatas) != count($classNames)) {
|
||||||
|
$this->fail("Have not found all classes matching the names '" . implode(", ", $classNames) . "' only tables " . implode(", ", array_keys($metadatas)));
|
||||||
|
}
|
||||||
|
return $metadatas;
|
||||||
|
}
|
||||||
|
}
|
30
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2387Test.php
Normal file
30
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2387Test.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\Tests\ORM\Functional\DatabaseDriverTestCase;
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
|
|
||||||
|
class DDC2387Test extends DatabaseDriverTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @group DDC-2387
|
||||||
|
*/
|
||||||
|
public function testCompositeAssociationKeyDetection()
|
||||||
|
{
|
||||||
|
$product = new \Doctrine\DBAL\Schema\Table('ddc2387_product');
|
||||||
|
$product->addColumn('id', 'integer');
|
||||||
|
$product->setPrimaryKey(array('id'));
|
||||||
|
|
||||||
|
$attributes = new \Doctrine\DBAL\Schema\Table('ddc2387_attributes');
|
||||||
|
$attributes->addColumn('product_id', 'integer');
|
||||||
|
$attributes->addColumn('attribute_name', 'string');
|
||||||
|
$attributes->setPrimaryKey(array('product_id', 'attribute_name'));
|
||||||
|
$attributes->addForeignKeyConstraint('ddc2387_product', array('product_id'), array('product_id'));
|
||||||
|
|
||||||
|
$metadata = $this->convertToClassMetadata(array($product, $attributes), array());
|
||||||
|
|
||||||
|
$this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $metadata['Ddc2387Attributes']->generatorType);
|
||||||
|
$this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_AUTO, $metadata['Ddc2387Product']->generatorType);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user