问题
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