What do you use instead of ENUM in doctrine2?

后端 未结 4 1800
半阙折子戏
半阙折子戏 2021-01-30 13:04

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

4条回答
  •  半阙折子戏
    2021-01-30 13:59

    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.

提交回复
热议问题