From 2ff76e44c076c7447d22ae2011c0f7a5bb0fe269 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Thu, 14 Jan 2010 15:48:42 +0000 Subject: [PATCH] [2.0][DDC-254] Improved MappingException thrown on missing required configuration of Many-Many mapping --- .../ORM/Mapping/ManyToManyMapping.php | 10 ++++++++-- lib/Doctrine/ORM/Mapping/MappingException.php | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php b/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php index 17b3c907e..9a868f9e4 100644 --- a/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php +++ b/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php @@ -83,11 +83,17 @@ class ManyToManyMapping extends AssociationMapping } // owning side MUST specify joinColumns if ( ! isset($mapping['joinTable']['joinColumns'])) { - throw MappingException::invalidMapping($this->_sourceFieldName); + throw MappingException::missingRequiredOption( + $this->sourceFieldName, 'joinColumns', + 'Did you think of case sensitivity / plural s?' + ); } // owning side MUST specify inverseJoinColumns if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) { - throw MappingException::invalidMapping($this->_sourceFieldName); + throw MappingException::missingRequiredOption( + $this->sourceFieldName, 'inverseJoinColumns', + 'Did you think of case sensitivity / plural s?' + ); } foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) { diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 2c76ba761..5c7f4676f 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -74,6 +74,26 @@ class MappingException extends \Doctrine\Common\DoctrineException return new self("The mapping of field '$fieldName' requires an the 'joinTable' attribute."); } + /** + * Called if a required option was not found but is required + * + * @param string $field which field cannot be processed? + * @param string $expectedOption which option is required + * @param string $hint Can optionally be used to supply a tip for common mistakes, + * e.g. "Did you think of the plural s?" + * @return MappingException + */ + static function missingRequiredOption($field, $expectedOption, $hint = '') + { + $message = "The mapping of field '{$field}' is invalid: The option '{$expectedOption}' is required."; + + if ( ! empty($hint)) { + $message .= ' (Hint: ' . $hint . ')'; + } + + return new self($message); + } + /** * Generic exception for invalid mappings. *