我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
属性匹配?
答案 0 :(得分:4)
没有办法做到这一点,也没有构建属性。
实际上,你不应该像你那样命名你的表属性,你应该低估它们:
<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
,...
威廉