stefanpolzer/propel-real-enum-behavior

Propel 2 行为,使枚举类型更接近枚举应有的行为

安装: 3

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 3

类型:propel-behavior

2.0.1 2024-03-11 14:49 UTC

This package is auto-updated.

Last update: 2024-09-11 15:54:25 UTC


README

Latest Stable Version Total Downloads License

需求

此行为是为 Propel 2 开发的。
它也只在 MySQL 数据库上进行了测试,如果您想对其进行测试或调整以适应其他数据库类型,请随时提交问题。

安装

composer require stefanpolzer/propel-real-enum-behavior

schema.xml

将行为添加到数据库的根目录或目标表中。
以下是一个示例:

<database ...>
    <!-- This will add the real-enum behavior for all enums in the database -->
    <behavior name="real-enum"/>
    <table name="my_table">        
        <column name="my_enum" type="ENUM" valueSet="FIRST,SECOND,THIRD" />
    </table>
</database>

用法

此行为执行了两个操作,以简化对 ENUMS 的使用

  • 现在您将在数据库中看到来自 valueSet 的枚举值,而不是数字。
  • 模型类现在将具有常量,以便轻松访问枚举值。使用上面的示例,我们可以从值集中获取值,如下所示:MyTable::MY_ENUM_SECOND