1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

[2.0][DDC-254] Improved MappingException thrown on missing required configuration of Many-Many mapping

This commit is contained in:
guilhermeblanco 2010-01-14 15:48:42 +00:00
parent 8ebd444966
commit 2ff76e44c0
2 changed files with 28 additions and 2 deletions

View file

@ -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) {

View file

@ -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.
*