Enum isn’t supported in Doctrine. I prefer to keep things as vanilla as possible so instead of registering a new type, we shall map it to a varchar.
You have to ensure that each varchar field that is an “enum” in the database only gets passed the allowed values. You can easily enforce this in your entities:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /** @Entity */ class Article { const STATUS_VISIBLE = 'visible'; const STATUS_INVISIBLE = 'invisible'; /** @Column(type="string") */ private $status; public function setStatus($status) { if (!in_array($status, array(self::STATUS_VISIBLE, self::STATUS_INVISIBLE))) { throw new \InvalidArgumentException("Invalid status"); } $this->status = $status; } } |
This is a lot easier to manage and requires no migration if you decide to add more options.
source: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/mysql-enums.html