Relational API: where() can not determine the column using namespaced classes

Deadly 提交于 2020-01-03 20:36:12

问题


Im trying to do something like this

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

but I get this error

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

While the same code in a non-namespaced context works fine.

I known that there are better ways to do it, but I want to known why this fails


回答1:


Well-known problem:

  • https://github.com/propelorm/Propel/issues/87
  • https://github.com/propelorm/Propel/issues/137

The best way to solve your problem is to use an alias:

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

The following code should work as well:

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

Regards, William




回答2:


Specifying the 3rd parameter, binding type, helped me:

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


来源:https://stackoverflow.com/questions/7289122/relational-api-where-can-not-determine-the-column-using-namespaced-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!