From 4ea3277c28303ca25356f25c8b7456525ed446b7 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 11 Nov 2010 21:13:03 +0100 Subject: [PATCH] DDC-856 - Add default "string" type to discriminator column, throw exception on specification of a bunch of invalid types --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 7 +++++++ lib/Doctrine/ORM/Mapping/MappingException.php | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 077eef1bc..2abf5269c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1442,6 +1442,13 @@ class ClassMetadataInfo 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']); + } + $this->discriminatorColumn = $columnDef; } } diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 8ea5be213..faf0e830c 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -207,6 +207,11 @@ class MappingException extends \Doctrine\ORM\ORMException return new self("Entity class '$className' is using inheritance but no discriminator column was defined."); } + public static function invalidDiscriminatorColumnType($className, $type) + { + return new self("Discriminator column type on entity class '$className' is not allowed to be '$type'. 'string' or 'integer' type variables are suggested!"); + } + /** * @param string $className * @param string $columnName @@ -216,4 +221,5 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping."); } + } \ No newline at end of file