[DDC-1746] Throw exception on invalid cascade option.
This commit is contained in:
parent
c5c3719e79
commit
5b18718b92
@ -1210,6 +1210,12 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
$cascades = array('remove', 'persist', 'refresh', 'merge', 'detach');
|
$cascades = array('remove', 'persist', 'refresh', 'merge', 'detach');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($cascades) !== count(array_intersect($cascades, array('remove', 'persist', 'refresh', 'merge', 'detach')))) {
|
||||||
|
throw MappingException::invalidCascadeOption(
|
||||||
|
array_diff($cascades, array_intersect($cascades, array('remove', 'persist', 'refresh', 'merge', 'detach')))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$mapping['cascade'] = $cascades;
|
$mapping['cascade'] = $cascades;
|
||||||
$mapping['isCascadeRemove'] = in_array('remove', $cascades);
|
$mapping['isCascadeRemove'] = in_array('remove', $cascades);
|
||||||
$mapping['isCascadePersist'] = in_array('persist', $cascades);
|
$mapping['isCascadePersist'] = in_array('persist', $cascades);
|
||||||
|
@ -354,4 +354,13 @@ class MappingException extends \Doctrine\ORM\ORMException
|
|||||||
{
|
{
|
||||||
return new self("The target-entity " . $targetEntity . " cannot be found in '" . $sourceEntity."#".$associationName."'.");
|
return new self("The target-entity " . $targetEntity . " cannot be found in '" . $sourceEntity."#".$associationName."'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function invalidCascadeOption(array $cascades)
|
||||||
|
{
|
||||||
|
$cascades = implode(", ", array_map(function ($e) { return "'" . $e . "'"; }, $cascades));
|
||||||
|
return new self(
|
||||||
|
"Invalid cascade option(s) specified: " . $cascades . ". " .
|
||||||
|
"Only 'remove', 'persist', 'refresh', 'merge' and 'detach' are allowed."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -637,6 +637,18 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertEquals('cms_cmsaddress_cms_cmsuser', $addressMetadata->associationMappings['user']['joinTable']['name']);
|
$this->assertEquals('cms_cmsaddress_cms_cmsuser', $addressMetadata->associationMappings['user']['joinTable']['name']);
|
||||||
$this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']);
|
$this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1746
|
||||||
|
*/
|
||||||
|
public function testInvalidCascade()
|
||||||
|
{
|
||||||
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||||
|
|
||||||
|
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Invalid cascade option(s) specified: 'invalid'. Only 'remove', 'persist', 'refresh', 'merge' and 'detach' are allowed.");
|
||||||
|
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => array('invalid')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyNamespacedNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy
|
class MyNamespacedNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy
|
||||||
|
Loading…
Reference in New Issue
Block a user