1
0
mirror of synced 2024-12-14 15:16:04 +03:00

Merge pull request #282 from FabioBatSilva/discriminatorColumnName

Mandatory discriminator column name
This commit is contained in:
Guilherme Blanco 2012-02-14 10:26:01 -08:00
commit 2c3c5b34cf
3 changed files with 22 additions and 3 deletions

View File

@ -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']);
}

View File

@ -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.");

View File

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