query->condition() with namespaced classes fails #87

meglio opened this Issue Sep 3, 2011 · 18 comments

8 participants



Here is the code that thrown a PropelException:

$userQuery = new \core\orm\UserQuery();
$userQuery->condition('email', 'User.Email = ?', $emailOrNick);

Please look at exception stack:
Exception Stack

Here is table definition in schema.xml:

<table name="users" phpName="User">
        <column name="id" type="BIGINT" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="notary_id" type="BIGINT" required="true"/>
        <column name="notary_admin" type="BOOLEAN" required="true" defaultValue="0"/>
        <column name="email" type="VARCHAR" size="180" required="false" description="Email is unique but not required for notary helpers. However it is strictly required for notary owners." />
        <column name="nick" type="VARCHAR" size="180" required="true" description="If only email specified, nickname will be set to email. This rule works for both notary owners and helpers."/>
        <column name="pass" type="LONGVARCHAR" required="true" />
        <column name="date_created" type="TIMESTAMP" required="true" defaultExpr="CURRENT_TIMESTAMP"/>
        <column name="date_authorized" type="TIMESTAMP" required="true" defaultExpr="CURRENT_TIMESTAMP"/>
        <column name="date_visited" type="TIMESTAMP" required="true" defaultExpr="CURRENT_TIMESTAMP"/>
        <column name="auth_token" type="VARCHAR" size="40" required="false" description="Authorization token - sha1 of some random key."/>
        <column name="active" type="BOOLEAN" defaultValue="1" description="Notary superuser can disable access for notary helper."/>
        <index name="ind_notary_ids">
            <index-column name="notary_id"/>
            <index-column name="notary_admin"/>
        <unique name="uniq_user_emails">
            <unique-column name="email"/>
        <unique name="uniq_user_nicks">
            <unique-column name="nick"/>
        <foreign-key name="frn_notary_of_user" foreignTable="notaries" onDelete="cascade" onUpdate="cascade">
            <reference local="notary_id" foreign="id" />
        <index name="ind_user_created">
            <index-column name="date_created"/>
        <index name="ind_user_authorized">
            <index-column name="date_authorized"/>
        <index name="ind_user_visited">
            <index-column name="date_visited"/>
        <index name="ind_user_passwords">
            <index-column name="pass"/>
        <unique name="uniq_user_auth_tokens">
            <unique-column name="auth_token"/>

I have also tried following but nothing worked:

$userQuery->condition('email', 'user.email = ?', $emailOrNick);
$userQuery->condition('email', 'user.Email = ?', $emailOrNick);
$userQuery->condition('email', 'User.email = ?', $emailOrNick);
$userQuery->condition('email', 'User.Email = ?', $emailOrNick);
$userQuery->condition('email', '\core\orm\User.Email = ?', $emailOrNick);
Propel member


To set a model alias will do the job.

$userQuery = new \core\orm\UserQuery();
$userQuery->condition('email', 'q.Email = ?', $emailOrNick);
@willdurand willdurand closed this Sep 12, 2011

Thanks, this worked. Can you explain another 2 things, please.

  1. Why must we use aliases?
  2. How to alias joined tables?
Propel member
  1. Because it solved your problem ;)
  2. In the join() method ?
  1. Can you please explain why it does not work without aliases, what is the reason?
  2. Yes, with join() - what if my where() will mention joined table, how must I alias it?



I think this is the bug I reported in the old bug tracker: http://trac.propelorm.org/ticket/1485


kesoil, yes really it looks like a bug, I see now.
willdurand, can you confirm it is bug and it will be fixed in future versions?

Propel member
@fzaninotto fzaninotto reopened this Oct 30, 2011
Propel member

Since it's a bug, let's reopen the Issue. @willdurand, can you take a look?

Propel member

Sure, but I thought it was solved..


It's not... as I mentioned on the dev-maillist, the ModelCriteria tries to find the matching Class by comparing it with the retrun value of getModelAliasOrName.
As far as I can see, this function will receive the full namespaced class name. And of course, \Vendor\MyBundle\MyClass != MyClass, so it cannot find anything

Propel member

of course it's a bug, but we fixed it in Propel 2 ;)

I will try to backport code from Propel2 and try to fix this issue (my collegue got it today ;) )

Propel member

this seems to be fixed in the latest propel version (I will tel my colleague to upgrade their propel 1.6.4 to last version) ;)

Propel member

@jaugustin is it ok?

Propel member

From my tests I say yes but my dev didn't take time to upgrade their propel version.

I think you could close the issue and if it's still broken I will reopen it ;)

Propel member


@willdurand willdurand closed this Apr 18, 2012


I got the same issue on 1.6.5 version

$query = ResourceQuery::create('alias')
            ->where("alias.Label LIKE ?",$string_query)

// Works but

    $query = ResourceQuery::create()
            ->where("Resource.Label LIKE ?",$string_query)


Is it solved ?


Same problem in 1.6.6.

$q = \Path\To\CategoryQuery::create();
$q->where('Category.Id = ?', 1);
PropelException: Cannot determine the column to bind to the parameter in clause 'Category.Id = ?'
in /var/www/workspaces/matt/mightyape/vendor/propel/propel1/runtime/lib/query/ModelCriteria.php
on line 1819
Propel member

we should first add tests in ModelCriteriaWithNamespaceTest to prove the issue and then fix it :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment