From f1571aeac373bcbc17ec3ebd133e78bbc1232e30 Mon Sep 17 00:00:00 2001
From: Philipp Scheit
Date: Mon, 21 May 2012 19:23:22 +0300
Subject: [PATCH] prevent the validator to stop with an "undefined array
index"-error while validating a wrong inversedBy Attribute
---
lib/Doctrine/ORM/Tools/SchemaValidator.php | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php
index 06456ac49..aa8528f02 100644
--- a/lib/Doctrine/ORM/Tools/SchemaValidator.php
+++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php
@@ -152,16 +152,18 @@ class SchemaValidator
}
// Verify inverse side/owning side match each other
- $targetAssoc = $targetMetadata->associationMappings[$assoc['inversedBy']];
- if ($assoc['type'] == ClassMetadataInfo::ONE_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_ONE){
- $ce[] = "If association " . $class->name . "#" . $fieldName . " is one-to-one, then the inversed " .
- "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-one as well.";
- } else if ($assoc['type'] == ClassMetadataInfo::MANY_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_MANY){
- $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-one, then the inversed " .
- "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-many.";
- } else if ($assoc['type'] == ClassMetadataInfo::MANY_TO_MANY && $targetAssoc['type'] !== ClassMetadataInfo::MANY_TO_MANY){
- $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-many, then the inversed " .
- "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be many-to-many as well.";
+ if (array_key_exists($assoc['inversedBy'], $targetMetadata->associationMappings)) {
+ $targetAssoc = $targetMetadata->associationMappings[$assoc['inversedBy']];
+ if ($assoc['type'] == ClassMetadataInfo::ONE_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_ONE){
+ $ce[] = "If association " . $class->name . "#" . $fieldName . " is one-to-one, then the inversed " .
+ "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-one as well.";
+ } else if ($assoc['type'] == ClassMetadataInfo::MANY_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_MANY){
+ $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-one, then the inversed " .
+ "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-many.";
+ } else if ($assoc['type'] == ClassMetadataInfo::MANY_TO_MANY && $targetAssoc['type'] !== ClassMetadataInfo::MANY_TO_MANY){
+ $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-many, then the inversed " .
+ "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be many-to-many as well.";
+ }
}
}