kodalto/propel-real-enum-behavior

Propel 2 行为,用于更紧密地管理 ENUM 类型,使其更接近枚举应有的表现

安装: 25

依赖者: 0

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 3

类型:propel-behavior

2.0.0 2023-05-12 21:48 UTC

This package is auto-updated.

Last update: 2024-09-13 00:38:22 UTC


README

Latest Stable Version Total Downloads License

需求

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

安装

composer require Kodalto/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 的 ENUM 值,而不是数字。
  • 模型类现在将具有常量,以便轻松访问枚举值。使用上面的示例,我们可以从值集中获取值,如下所示: MyTable::MY_ENUM_SECOND