你在doctrine2中使用什么而不是ENUM? [英] What do you use instead of ENUM in doctrine2?

查看:75
本文介绍了你在doctrine2中使用什么而不是ENUM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你在Doctrine2中使用什么而不是ENUM? SMALLINT?我想到使用varchar,或者明确定义char,但是在索引上可能不是非常有效,或者我错了?

解决方案

我通常使用映射到类常量的整数,如

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆