Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1.4, 1.2.0-ALPHA1
-
Fix Version/s: 1.1.4, 1.2.0-ALPHA2
-
Component/s: Nested Set, Query
-
Labels:None
Description
When trying to fetch a nested set tree, where a base query uses join, an exception is thrown "'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'", which is caused by incorrect generated SQL query.
How to reproduce:
$query = Doctrine_Query::create()
->select('s.name')
->from('Test s')
->leftJoin('s.Test2 st WITH st.title = ?', array(1));
$tree_table = Doctrine::getTable('Test');
$tree = $tree_table->getTree();
viewing SQL at this point, is:
SELECT t.id AS t__id, t.name AS t__name FROM test t LEFT JOIN test_2 t2 ON t.id = t2.test_id AND (t2.title = ?)
set the query as a base for nestedSet tree:
$tree->setBaseQuery($query);
viewing SQL at this point, is:
SELECT t.id AS t__id, t.name AS t__name, t.lft AS t__lft, t.rgt AS t__rgt, t.level AS t__level FROM test t LEFT JOIN test_2 t2 ON t.id = t2.test_id AND (t2.title = ?) AND (t2.title = ?)
As you can see lft/rgt/level fields were added, which is ok, but also additional LEFT JOIN condition was duplicated - (t2.title = ?) .
These kind of queries are working in 1.0* branch and also seemed to work in 1.1* branch until 5680 revision, which broke it. Although Changeset 5700 seems to must have fixed it, but the SQL is still generated doubled in 1.1* and 1.2* branches.
TestCase from ticket 2105 (which was fixed in rev. 5700) works ok. (BTW. It was my ticket
)
Create a failing testcase for that, it will help devs.