Commit dc5e0cee authored by zYne's avatar zYne

fixes #515, correlated subqueries with IN operator

parent 991f456f
......@@ -97,7 +97,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
// subquery found
$q = new Doctrine_Query();
$value = '(' . $q->isSubquery(true)->parseQuery($trimmed)->getQuery() . ')';
$value = '(' . $this->query->createSubquery()->parseQuery($trimmed, false)->getQuery() . ')';
} elseif (substr($trimmed, 0, 4) == 'SQL:') {
$value = '(' . substr($trimmed, 4) . ')';
......
......@@ -315,4 +315,13 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getSql(), 'SELECT e.id AS e__id FROM entity e WHERE 1 IN (1, 2) AND (e.type = 0)');
}
public function testCorrelatedSubqueryWithInOperatorIsSupported()
{
$q = new Doctrine_Query();
$q->select('u.id')->from('User u')->where('u.name IN (SELECT u2.name FROM User u2 WHERE u2.id = u.id)');
$this->assertEqual($q->getSql(), 'SELECT e.id AS e__id FROM entity e WHERE e.name IN (SELECT e2.name AS e2__name FROM entity e2 WHERE e2.id = e.id AND (e.type = 0 AND (e2.type = 0 OR e2.type IS NULL))) AND (e.type = 0)');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment