From 86583767136d223908c1a4c441075badb77157d0 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 30 Dec 2010 23:18:00 +0100 Subject: [PATCH] DDC-929 - Fix bug with DatabaseDriver not detecting indexes that are not called primary. --- lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index c6c4547b6..0dc6a05e0 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -22,6 +22,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Cache\ArrayCache, Doctrine\Common\Annotations\AnnotationReader, Doctrine\DBAL\Schema\AbstractSchemaManager, + Doctrine\DBAL\Schema\SchemaException, Doctrine\ORM\Mapping\ClassMetadataInfo, Doctrine\ORM\Mapping\MappingException, Doctrine\Common\Util\Inflector; @@ -128,6 +129,11 @@ class DatabaseDriver implements Driver $columns = $this->tables[$tableName]->getColumns(); $indexes = $this->tables[$tableName]->getIndexes(); + try { + $primaryKeyColumns = $this->tables[$tableName]->getPrimaryKey()->getColumns(); + } catch(SchemaException $e) { + $primaryKeyColumns = array(); + } if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $foreignKeys = $this->tables[$tableName]->getForeignKeys(); @@ -144,7 +150,7 @@ class DatabaseDriver implements Driver $fieldMappings = array(); foreach ($columns as $column) { $fieldMapping = array(); - if (isset($indexes['primary']) && in_array($column->getName(), $indexes['primary']->getColumns())) { + if ($primaryKeyColumns && in_array($column->getName(), $primaryKeyColumns)) { $fieldMapping['id'] = true; } else if (in_array($column->getName(), $allForeignKeyColumns)) { continue;