What do you use instead of ENUM in Doctrine2? smallint? I thought of using varchar, or explicitly define char, but this may not be very effective when it comes to indexes, or am
If you want MySQL ENUMs using MySQL and Symfony, you can now use an easy way for that without any dependencies
values);
return "ENUM(".implode(", ", $values).")";
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return $value;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (!in_array($value, $this->values)) {
throw new \InvalidArgumentException("Invalid '".$this->name."' value.");
}
return $value;
}
public function getName()
{
return $this->name;
}
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
}
namespace App\Enum;
class UploadFileStatusType extends EnumType
{
const OPEN = 'open';
const DONE = 'done';
const ERROR = 'error';
protected $name = self::class;
protected $values = [
self::OPEN => self::OPEN ,
self::DONE => self::DONE,
self::ERROR => self::ERROR,
];
}
doctrine:
dbal:
types:
UploadFileStatusType: App\Enum\UploadFileStatusType
class MyEntity
{
/**
* @var string
*
* @ORM\Column(type="UploadFileStatusType")
*/
protected $status;
}
enum('open', 'done', 'error')