Commit 2ff76e44 authored by guilhermeblanco's avatar guilhermeblanco

[2.0][DDC-254] Improved MappingException thrown on missing required...

[2.0][DDC-254] Improved MappingException thrown on missing required configuration of Many-Many mapping
parent 8ebd4449
......@@ -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.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment