Search code examples
phpnamespacespropel

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


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


Solution

  • Well-known problem:

    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