diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index b71889d40..0e579df63 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -132,14 +132,16 @@ class DatabaseDriver implements Driver "Cannot generate mapping for table '".$tableName."' with foreign keys with multiple local columns." ); } - $localColumn = current($foreignKey->getColumns()); + $cols = $foreignKey->getColumns(); + $localColumn = current($cols); - if (count($foreignKey->getForeignColumns()) != 1) { + $fkCols = $foreignKey->getForeignColumns(); + if (count($fkCols) != 1) { throw new MappingException( "Cannot generate mapping for table '".$tableName."' with foreign keys with multiple foreign columns." ); } - $foreignColumn = current($foreignKey->getForeignColumns()); + $foreignColumn = current($fkCols); $associationMapping = array(); $associationMapping['fieldName'] = Inflector::camelize(str_ireplace('_id', '', $localColumn)); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 183d4ec56..b0c06ce9b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -346,7 +346,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest $this->assertFalse($table->hasIndex('foo_idx')); $this->assertEquals(1, count($table->getForeignKeys())); - $foreignKey = current($table->getForeignKeys()); + $fks = $table->getForeignKeys(); + $foreignKey = current($fks); $this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName())); $this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns())); $this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));