I want to implement the Class Table Inheritance:
/**
* Foo
*
* @ORM\Table(name="foos", ...)
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({
* "bar" = "Bar",
* "buz" = "Buz"
* })
*/
abstract class Foo
{
...
}
Since I run the "code first" approach, the database is generated by Doctrine:
$ bin/console doctrine:migrations:diff
$ bin/console doctrine:migrations:migrate
The discriminator column foos.type gets the type VARCHAR(255). I want it to get an ENUM instead.
How to define the annotation for the entity class for getting an ENUM discriminator?
It works with
columnDefinition="ENUM('bar', 'buz')":Unfortunately it causes an annoying side effect (s. also here): The migration mechanism of Doctrine seems to handle
ENUMs incorrectly. Thedoctrine:migrations:diffcommand creates a migration like this:I execute it, the
typecolumn become anENUM. But a new executing ofdoctrine:migrations:diffcreates a migration with the same content again... Means, Doctrine "thinks", the column is stillVARCHAR.