编程语言
首页 > 编程语言> > 推进区分大小写的phpNames列

推进区分大小写的phpNames列

作者:互联网

我的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

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

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

解决方法:

没有办法,也没有build属性.

实际上,您不应该像以前那样命名表属性,而应该对它们进行低估:

<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,…

威廉

标签:propel,mysql,php
来源: https://codeday.me/bug/20191102/1987908.html