Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Namespace causes getCriterionForClause to fail #137

nikcorg opened this Issue Oct 11, 2011 · 3 comments


None yet
2 participants

nikcorg commented Oct 11, 2011

I stumbled upon a scenario where ModelCriteria::getCriterionForClause would fail with the exception Cannot determine the column to bind to the parameter in clause 'CampaignName.Enabled = ?', even though the column in question is indeed defined in schema.xml and in the TableMap class.

A workaround for the issue was found when asking for help on Propel's excellent irc-channel, but the suspicion that the behaviour is indeed a bug and specifically related to namespaces arose while analyzing the problem.

Without further ado, here are the details.

The relevant parts of the schema:

<?xml version="1.0" encoding="utf-8"?>
<!--Autogenerated by PropelSchemaReverseTask class.-->
<database name="tod" defaultIdMethod="native">
<table namespace="\tod\models" package="tod.models" name="campaign_name" phpName="CampaignName" idMethod="native">
    <column name="enabled" phpName="Enabled" type="TINYINT" size="3" sqlType="tinyint(3) unsigned" required="false" defaultValue="1"/>

The failing query:

    ->where('CampaignName.Enabled = ?', 1) 

// Fails with: `Cannot determine the column to bind to the parameter in clause 'CampaignName.Enabled = ?'`

The workaround:

    ->where('cn.Enabled = ?')

pylebecq commented Oct 12, 2011

I ran into the same issue.

The thing is that ModelCriteria::replaceNames() (called by ModelCriteria::getCriterionForClause()) uses a preg_replace_callback() with a pattern that does not match namespaced models.

So, I tweaked the pattern to :
preg_replace_callback("/[\w\\\]+\.\w+/", array($this, 'doReplaceNameInExpression'), $stringToTransform);
Now, I can use fully qualified class name in the clause and it works. For example :

->where('Acme\\CampaignBundle\\Model\\CampaignName.Enabled = ?', 1)

Maybe I should do a PR for this, but my query is still failing because of SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters] (It is a quite complex query, using condition() and combine() several times.)


pylebecq commented Oct 17, 2011

I think the issue could be closed since the PR got merged.

nikcorg commented Oct 17, 2011

Closed, as issue was resolved in #138

@nikcorg nikcorg closed this Oct 17, 2011

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