From de5e4b0fdcdcbba0304638797e6af41b92fa31e7 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 14 Mar 2012 21:09:48 +0100 Subject: [PATCH] [DBAL-1692] Throw exception if table has no primary key instead of fatal error. --- lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 2b73ed9fb..8d6136ac5 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -130,6 +130,13 @@ class DatabaseDriver implements Driver $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns()); } + if ( ! $table->hasPrimaryKey()) { + throw new MappingException( + "Table " . $table->getName() . " has no primary key. Doctrine does not ". + "support reverse engineering from tables that don't have a primary key." + ); + } + $pkColumns = $table->getPrimaryKey()->getColumns(); sort($pkColumns); sort($allForeignKeyColumns);