stefanpolzer / propel-real-enum-behavior
Propel 2 行为,使枚举类型更接近枚举应有的行为
2.0.1
2024-03-11 14:49 UTC
Requires
- php: >=7.4
- propel/propel: ~2.0@beta
This package is auto-updated.
Last update: 2024-09-11 15:54:25 UTC
README
需求
此行为是为 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