推动列区分大小写的 phpNames

发布于 2024-12-17 04:40:12 字数 2499 浏览 0 评论 0原文

我的 schema.xml 的相关部分:

<database name="Inventory" defaultIdMethod="native">
  <table name="Users" phpName="User">
    <column name="UserId" type="varchar" size="20" required="true" primaryKey="true" />
    <column name="FirstName" type="varchar" size="255" required="true" />
    <column name="LastName" type="varchar" size="255" required="true" />
    <column name="Password" type="varchar" size="255" required="true" />
    <column name="Salt" type="char" size="22" required="true" />
    <column name="RoleId" type="integer" required="true" />
    <column name="FailedLogins" type="integer" required="true" defaultValue="0" />
    <column name="LockedOut" type="boolean" required="true" defaultValue="false" />
    <column name="Active" type="boolean" required="true" defaultValue="true" />
  </table>
...
</database>

以下命令失败并出现 PropelException

UserQuery::create()
    ->filterByActive(true)
    ->update(array('FailedLogins' => 0, 'LockedOut' => false));

错误:

[Sat Nov 19 16:28:01 2011] [error] [client 127.0.0.11] PHP Fatal error:  Uncaught exception 'PropelException' with message 'Cannot fetch ColumnMap for undefined column phpName: FailedLogins' in /home/andrew/pss-repository/vendor/propel/runtime/lib/map/TableMap.php:372\nStack trace:\n#0 /home/andrew/pss-repository/vendor/propel/runtime/lib/query/ModelCriteria.php(1668): TableMap->getColumnByPhpName('FailedLogins')\n#1 /home/andrew/pss-repository/vendor/propel/runtime/lib/query/ModelCriteria.php(1626): ModelCriteria->doUpdate(Array, Object(PropelPDO), false)\n#2 /home/andrew/pss-repository/login-reset-process.php(11): ModelCriteria->update(Array)\n#3 {main}\n  thrown in /home/andrew/pss-repository/vendor/propel/runtime/lib/map/TableMap.php on line 372, referer: http://pss/login-reset-all.php

我能够验证 FailedLogins 列在 Propel 生成的代码中被标识为 Failedlogins。我意识到我可以将 phpName 添加到相关列中,但我想知道我是否错过了配置选项。我检查了 Propel buildtime 配置页面,我看到一个名为 的选项propel.samePhpName,但由于它位于“逆向工程”部分下,因此它似乎不是我需要的选项。其他人问过类似问题,但我没有看到一个明确的答案。

是否有一个配置选项可以使每列的 phpName 与架构中的 name 属性简单匹配?

The relevant portion of my schema.xml:

<database name="Inventory" defaultIdMethod="native">
  <table name="Users" phpName="User">
    <column name="UserId" type="varchar" size="20" required="true" primaryKey="true" />
    <column name="FirstName" type="varchar" size="255" required="true" />
    <column name="LastName" type="varchar" size="255" required="true" />
    <column name="Password" type="varchar" size="255" required="true" />
    <column name="Salt" type="char" size="22" required="true" />
    <column name="RoleId" type="integer" required="true" />
    <column name="FailedLogins" type="integer" required="true" defaultValue="0" />
    <column name="LockedOut" type="boolean" required="true" defaultValue="false" />
    <column name="Active" type="boolean" required="true" defaultValue="true" />
  </table>
...
</database>

The following command fails with a PropelException:

UserQuery::create()
    ->filterByActive(true)
    ->update(array('FailedLogins' => 0, 'LockedOut' => false));

The error:

[Sat Nov 19 16:28:01 2011] [error] [client 127.0.0.11] PHP Fatal error:  Uncaught exception 'PropelException' with message 'Cannot fetch ColumnMap for undefined column phpName: FailedLogins' in /home/andrew/pss-repository/vendor/propel/runtime/lib/map/TableMap.php:372\nStack trace:\n#0 /home/andrew/pss-repository/vendor/propel/runtime/lib/query/ModelCriteria.php(1668): TableMap->getColumnByPhpName('FailedLogins')\n#1 /home/andrew/pss-repository/vendor/propel/runtime/lib/query/ModelCriteria.php(1626): ModelCriteria->doUpdate(Array, Object(PropelPDO), false)\n#2 /home/andrew/pss-repository/login-reset-process.php(11): ModelCriteria->update(Array)\n#3 {main}\n  thrown in /home/andrew/pss-repository/vendor/propel/runtime/lib/map/TableMap.php on line 372, referer: http://pss/login-reset-all.php

I am able to verify that the FailedLogins column is identified as Failedlogins in the Propel-generated code. I realize that I can probably add phpName to the columns in question, but I was wondering if I have missed a configuration option. I checked the Propel buildtime configuration page, and I see an option called propel.samePhpName, but as it is under the "Reverse Engineering" section it does not appear to be the option I need. Others have asked similar questions, but I have not seen a clear answer.

Is there a configuration option to make the phpName of each column simply match the name attribute in the schema?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2024-12-24 04:40:12

不,没有办法做到这一点,也没有建造财产。

实际上,你不应该像你那样命名你的表属性,你应该给它们下划线:

<table name="Users" phpName="User">
  <column name="user_id" type="varchar" size="20" required="true" primaryKey="true" />
  <column name="first_name" type="varchar" size="255" required="true" />
  <column name="last_name" type="varchar" size="255" required="true" />
  <column name="password" type="varchar" size="255" required="true" />
  <column name="salt" type="char" size="22" required="true" />
  <column name="role_id" type="integer" required="true" />
  <column name="failed_logins" type="integer" required="true" defaultValue="0" />
  <column name="locked_out" type="boolean" required="true" defaultValue="false" />
  <column name="active" type="boolean" required="true" defaultValue="true" />
</table>

这样你就会得到 UserId, ..., FailedLogins, ...

William

No there is no way to do that, nor a build property.

Actually, you should not name your table attributes like you did, you should underscorize them:

<table name="Users" phpName="User">
  <column name="user_id" type="varchar" size="20" required="true" primaryKey="true" />
  <column name="first_name" type="varchar" size="255" required="true" />
  <column name="last_name" type="varchar" size="255" required="true" />
  <column name="password" type="varchar" size="255" required="true" />
  <column name="salt" type="char" size="22" required="true" />
  <column name="role_id" type="integer" required="true" />
  <column name="failed_logins" type="integer" required="true" defaultValue="0" />
  <column name="locked_out" type="boolean" required="true" defaultValue="false" />
  <column name="active" type="boolean" required="true" defaultValue="true" />
</table>

That way you'll get UserId, …, FailedLogins, …

William

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文