你在doctrine2中使用什么而不是ENUM? [英] What do you use instead of ENUM in doctrine2?
问题描述
我通常使用映射到类常量的整数,如
class MyEntity {
const STATUS_INACTIVE = 0 ;
const STATUS_ACTIVE = 1;
const STATUS_REFUSE = 2;
protected $ status = self :: STATUS_ACTIVE;
}
这个工作很好,使你更容易处理你所说的IDE中的ENUMS。
您还可以使用文档中描述的可枚举类型,但这意味着您必须为每个枚举列定义一个自定义类型。这是很多工作,没有真正的好处。
您可能还想知道为什么你不应该真的使用枚举。
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 I wrong?
I usually work with integers mapped to class constants, like
class MyEntity {
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
const STATUS_REFUSE = 2;
protected $status = self::STATUS_ACTIVE;
}
That works quite fine and makes it even easier to work with what you would call ENUMS in an IDE.
You can also use an enumerable type as described by the documentation, but that means you will have to define one custom type per enum column. That's a lot of work with no real benefit.
You may also want to know why you shouldn't really use enums.
这篇关于你在doctrine2中使用什么而不是ENUM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!