Added support to SingleValuePathExpression in ORDER BY.
This commit is contained in:
parent
63a2f02f4d
commit
a0ca506db7
@ -1342,10 +1342,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OrderByItem ::= (ResultVariable | StateFieldPathExpression) ["ASC" | "DESC"]
|
* OrderByItem ::= (ResultVariable | SingleValuedPathExpression) ["ASC" | "DESC"]
|
||||||
*
|
|
||||||
* @todo Post 2.0 release. Support general SingleValuedPathExpression instead
|
|
||||||
* of only StateFieldPathExpression.
|
|
||||||
*
|
*
|
||||||
* @return \Doctrine\ORM\Query\AST\OrderByItem
|
* @return \Doctrine\ORM\Query\AST\OrderByItem
|
||||||
*/
|
*/
|
||||||
@ -1360,7 +1357,7 @@ class Parser
|
|||||||
$token = $this->_lexer->lookahead;
|
$token = $this->_lexer->lookahead;
|
||||||
$expr = $this->ResultVariable();
|
$expr = $this->ResultVariable();
|
||||||
} else {
|
} else {
|
||||||
$expr = $this->StateFieldPathExpression();
|
$expr = $this->SingleValuedPathExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = new AST\OrderByItem($expr);
|
$item = new AST\OrderByItem($expr);
|
||||||
|
@ -479,20 +479,20 @@ class SqlWalker implements TreeWalker
|
|||||||
|
|
||||||
$assoc = $class->associationMappings[$fieldName];
|
$assoc = $class->associationMappings[$fieldName];
|
||||||
|
|
||||||
if ($assoc['isOwningSide']) {
|
if ( ! $assoc['isOwningSide']) {
|
||||||
// COMPOSITE KEYS NOT (YET?) SUPPORTED
|
|
||||||
if (count($assoc['sourceToTargetKeyColumns']) > 1) {
|
|
||||||
throw QueryException::associationPathCompositeKeyNotSupported();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_useSqlTableAliases) {
|
|
||||||
$sql .= $this->getSQLTableAlias($class->table['name'], $dqlAlias) . '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql .= reset($assoc['targetToSourceKeyColumns']);
|
|
||||||
} else {
|
|
||||||
throw QueryException::associationPathInverseSideNotSupported();
|
throw QueryException::associationPathInverseSideNotSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// COMPOSITE KEYS NOT (YET?) SUPPORTED
|
||||||
|
if (count($assoc['sourceToTargetKeyColumns']) > 1) {
|
||||||
|
throw QueryException::associationPathCompositeKeyNotSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_useSqlTableAliases) {
|
||||||
|
$sql .= $this->getSQLTableAlias($class->table['name'], $dqlAlias) . '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= reset($assoc['targetToSourceKeyColumns']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -39,7 +39,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$query->setHint($name, $value);
|
$query->setHint($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::assertEquals($sqlToBeConfirmed, $query->getSql());
|
parent::assertEquals($sqlToBeConfirmed, $query->getSQL());
|
||||||
$query->free();
|
$query->free();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->fail($e->getMessage() ."\n".$e->getTraceAsString());
|
$this->fail($e->getMessage() ."\n".$e->getTraceAsString());
|
||||||
@ -678,6 +678,23 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT COUNT(*) FROM cms_articles c1_ WHERE c1_.user_id = c0_.id) AS sclr4 FROM cms_users c0_ ORDER BY sclr4 ASC"
|
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT COUNT(*) FROM cms_articles c1_ WHERE c1_.user_id = c0_.id) AS sclr4 FROM cms_users c0_ ORDER BY sclr4 ASC"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOrderBySupportsSingleValuedPathExpressionOwningSide()
|
||||||
|
{
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
"select a from Doctrine\Tests\Models\CMS\CmsArticle a order by a.user",
|
||||||
|
"SELECT c0_.id AS id0, c0_.topic AS topic1, c0_.text AS text2, c0_.version AS version3 FROM cms_articles c0_ ORDER BY c0_.user_id ASC"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Doctrine\ORM\Query\QueryException
|
||||||
|
*/
|
||||||
|
public function testOrderBySupportsSingleValuedPathExpressionInverseSide()
|
||||||
|
{
|
||||||
|
$q = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u order by u.address");
|
||||||
|
$q->getSQL();
|
||||||
|
}
|
||||||
|
|
||||||
public function testBooleanLiteralInWhereOnSqlite()
|
public function testBooleanLiteralInWhereOnSqlite()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user