[2.0][DDC-254] Improved MappingException thrown on missing required configuration of Many-Many mapping
This commit is contained in:
parent
8ebd444966
commit
2ff76e44c0
2 changed files with 28 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue