1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Added support to SingleValuePathExpression in ORDER BY.

This commit is contained in:
Guilherme Blanco 2011-08-14 00:46:02 -03:00
parent 63a2f02f4d
commit a0ca506db7
3 changed files with 32 additions and 18 deletions

View File

@ -1342,10 +1342,7 @@ class Parser
}
/**
* OrderByItem ::= (ResultVariable | StateFieldPathExpression) ["ASC" | "DESC"]
*
* @todo Post 2.0 release. Support general SingleValuedPathExpression instead
* of only StateFieldPathExpression.
* OrderByItem ::= (ResultVariable | SingleValuedPathExpression) ["ASC" | "DESC"]
*
* @return \Doctrine\ORM\Query\AST\OrderByItem
*/
@ -1360,7 +1357,7 @@ class Parser
$token = $this->_lexer->lookahead;
$expr = $this->ResultVariable();
} else {
$expr = $this->StateFieldPathExpression();
$expr = $this->SingleValuedPathExpression();
}
$item = new AST\OrderByItem($expr);

View File

@ -479,20 +479,20 @@ class SqlWalker implements TreeWalker
$assoc = $class->associationMappings[$fieldName];
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 {
if ( ! $assoc['isOwningSide']) {
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;
default:

View File

@ -39,7 +39,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
$query->setHint($name, $value);
}
parent::assertEquals($sqlToBeConfirmed, $query->getSql());
parent::assertEquals($sqlToBeConfirmed, $query->getSQL());
$query->free();
} catch (\Exception $e) {
$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"
);
}
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()
{