Merge pull request #282 from FabioBatSilva/discriminatorColumnName
Mandatory discriminator column name
This commit is contained in:
commit
2c3c5b34cf
@ -1937,19 +1937,22 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
public function setDiscriminatorColumn($columnDef)
|
||||
{
|
||||
if ($columnDef !== null) {
|
||||
if ( ! isset($columnDef['name'])) {
|
||||
throw MappingException::nameIsMandatoryForDiscriminatorColumns($this->name);
|
||||
}
|
||||
|
||||
if (isset($this->fieldNames[$columnDef['name']])) {
|
||||
throw MappingException::duplicateColumnName($this->name, $columnDef['name']);
|
||||
}
|
||||
|
||||
if ( ! isset($columnDef['name'])) {
|
||||
throw MappingException::nameIsMandatoryForDiscriminatorColumns($this->name, $columnDef);
|
||||
}
|
||||
if ( ! isset($columnDef['fieldName'])) {
|
||||
$columnDef['fieldName'] = $columnDef['name'];
|
||||
}
|
||||
|
||||
if ( ! isset($columnDef['type'])) {
|
||||
$columnDef['type'] = "string";
|
||||
}
|
||||
|
||||
if (in_array($columnDef['type'], array("boolean", "array", "object", "datetime", "time", "date"))) {
|
||||
throw MappingException::invalidDiscriminatorColumnType($this->name, $columnDef['type']);
|
||||
}
|
||||
|
@ -226,6 +226,11 @@ class MappingException extends \Doctrine\ORM\ORMException
|
||||
return new self("Discriminator column type on entity class '$className' is not allowed to be '$type'. 'string' or 'integer' type variables are suggested!");
|
||||
}
|
||||
|
||||
public static function nameIsMandatoryForDiscriminatorColumns($className)
|
||||
{
|
||||
return new self("Discriminator column name on entity class '$className' is not defined.");
|
||||
}
|
||||
|
||||
public static function cannotVersionIdField($className, $fieldName)
|
||||
{
|
||||
return new self("Setting Id field '$fieldName' as versionale in entity class '$className' is not supported.");
|
||||
|
@ -596,6 +596,17 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
||||
$cm->validateAssocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Doctrine\ORM\Mapping\MappingException
|
||||
* @expectedExceptionMessage Discriminator column name on entity class 'Doctrine\Tests\Models\CMS\CmsUser' is not defined.
|
||||
*/
|
||||
public function testNameIsMandatoryForDiscriminatorColumnsMappingException()
|
||||
{
|
||||
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
$cm->setDiscriminatorColumn(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-984
|
||||
* @group DDC-559
|
||||
|
Loading…
Reference in New Issue
Block a user