From a82bffbfc99101319883423c4bdfbf88fd7cb92a Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 15 Oct 2011 20:31:56 +0200 Subject: [PATCH] Make SchemaValidator catch errors such as very invalid schema using only part of the primary key for join columns --- lib/Doctrine/ORM/Tools/SchemaValidator.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index 8acaa0b54..a7f8e3a1c 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -152,6 +152,17 @@ class SchemaValidator "has to be a primary key column."; } } + + if (count($targetClass->identifier) != count($assoc['joinTable']['inverseJoinColumns'])) { + $ce[] = "The inverse join columns of the many-to-many table '" . $assoc['joinTable']['name'] . "' " . + "have to match to ALL identifier columns of the target entity '". $targetClass->name . "'"; + } + + if (count($class->identifier) != count($assoc['joinTable']['joinColumns'])) { + $ce[] = "The join columns of the many-to-many table '" . $assoc['joinTable']['name'] . "' " . + "have to match to ALL identifier columns of the source entity '". $class->name . "'"; + } + } else if ($assoc['type'] & ClassMetadataInfo::TO_ONE) { foreach ($assoc['joinColumns'] AS $joinColumn) { $targetClass = $cmf->getMetadataFor($assoc['targetEntity']); @@ -167,6 +178,11 @@ class SchemaValidator "has to be a primary key column."; } } + + if (count($class->identifier) != count($assoc['joinColumns'])) { + $ce[] = "The join columns of the association '" . $assoc['fieldName'] . "' " . + "have to match to ALL identifier columns of the source entity '". $class->name . "'"; + } } }