php - 关系API : where() can not determine the column using namespaced classes

标签 php namespaces propel

我正在尝试做这样的事情

$u = \Entity\UserQuery::create()->where('User.Username = ?', "john")->findOne();

但我收到此错误

Cannot determine the column to bind to the parameter in clause 'User.Username = ?'

虽然相同的代码在非命名空间上下文中工作正常。

我知道有更好的方法可以做到这一点,但我想知道为什么会失败

最佳答案

众所周知的问题:

解决问题的最佳方法是使用别名:

$u = \Entity\UserQuery::create('alias')
    ->where('alias.Username = ?', "john")
    ->findOne();

下面的代码应该也可以工作:

$u = \Entity\UserQuery::create('alias')
    ->where('Entity\UserQuery.Username = ?', "john") // or ->where('\Entity\UserQuery.Username = ?', "john")
    ->findOne();

问候, 威廉

关于php - 关系API : where() can not determine the column using namespaced classes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7289122/

相关文章:

mysql - Propel Criteria::setLimit() 像 LIMIT 0,6

php - 找不到推进配置文件

php - 国家/地区/城市数据库

ubuntu - 如何为每个用户配置msmtprc

php - Laravel Eloquent 在不同连接上急切加载

R 命名空间访问和 match.fun

php - php中的trim()和strip_tags()可以防止sql注入(inject)吗?

c# - 可重用组件的命名空间和程序集名称

c# - 找不到使用 System.Web.UI.HtmlControls 命名空间

symfony1 - Symfony 推进查询