diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php index cbed1adb946..cd6741fea6d 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php @@ -46,10 +46,9 @@ class SizeFunction extends FunctionNode public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { $dqlAlias = $this->collectionPathExpression->identificationVariable; - $parts = $this->collectionPathExpression->parts; - $assocField = array_pop($parts); - - $qComp = $sqlWalker->getQueryComponent(implode('.', array_merge((array) $dqlAlias, $parts))); + $assocField = $this->collectionPathExpression->field; + + $qComp = $sqlWalker->getQueryComponent($dqlAlias); $assoc = $qComp['metadata']->associationMappings[$assocField]; $sql = ''; diff --git a/lib/Doctrine/ORM/Query/AST/PathExpression.php b/lib/Doctrine/ORM/Query/AST/PathExpression.php index ed856f67954..45042c2ea2a 100644 --- a/lib/Doctrine/ORM/Query/AST/PathExpression.php +++ b/lib/Doctrine/ORM/Query/AST/PathExpression.php @@ -23,11 +23,10 @@ * AssociationPathExpression ::= CollectionValuedPathExpression | SingleValuedAssociationPathExpression * SingleValuedPathExpression ::= StateFieldPathExpression | SingleValuedAssociationPathExpression * StateFieldPathExpression ::= SimpleStateFieldPathExpression | SimpleStateFieldAssociationPathExpression - * SingleValuedAssociationPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* SingleValuedAssociationField - * CollectionValuedPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* CollectionValuedAssociationField + * SingleValuedAssociationPathExpression ::= IdentificationVariable "." SingleValuedAssociationField + * CollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField * StateField ::= {EmbeddedClassStateField "."}* SimpleStateField * SimpleStateFieldPathExpression ::= IdentificationVariable "." StateField - * SimpleStateFieldAssociationPathExpression ::= SingleValuedAssociationPathExpression "." StateField * * @since 2.0 * @author Guilherme Blanco @@ -43,13 +42,13 @@ class PathExpression extends Node public $type; public $expectedType; public $identificationVariable; - public $parts; + public $field; - public function __construct($expectedType, $identificationVariable, array $parts) + public function __construct($expectedType, $identificationVariable, $field = null) { $this->expectedType = $expectedType; $this->identificationVariable = $identificationVariable; - $this->parts = $parts; + $this->field = $field; } public function dispatch($walker) diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index d6f35568434..62d8b314aeb 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -84,7 +84,7 @@ public function __construct(AST\Node $AST, $sqlWalker) $updateSql = 'UPDATE ' . $class->getQuotedTableName($platform) . ' SET '; foreach ($updateItems as $updateItem) { - $field = $updateItem->pathExpression->parts[0]; + $field = $updateItem->pathExpression->field; if (isset($class->fieldMappings[$field]) && ! isset($class->fieldMappings[$field]['inherited']) || isset($class->associationMappings[$field]) && ! $class->associationMappings[$field]->inherited) { $newValue = $updateItem->newValue; diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 96ff91bf78f..a01162453f6 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -490,6 +490,7 @@ private function _processDeferredPartialObjectExpressions() foreach ($this->_deferredPartialObjectExpressions as $deferredItem) { $expr = $deferredItem['expression']; $class = $this->_queryComponents[$expr->identificationVariable]['metadata']; + foreach ($expr->partialFieldSet as $field) { if ( ! isset($class->fieldMappings[$field])) { $this->semanticalError( @@ -498,6 +499,7 @@ private function _processDeferredPartialObjectExpressions() ); } } + if (array_intersect($class->identifier, $expr->partialFieldSet) != $class->identifier) { $this->semanticalError( "The partial field selection of class " . $class->name . " must contain the identifier.", @@ -548,9 +550,9 @@ private function _processDeferredResultVariables() * * AssociationPathExpression ::= CollectionValuedPathExpression | SingleValuedAssociationPathExpression * SingleValuedPathExpression ::= StateFieldPathExpression | SingleValuedAssociationPathExpression - * StateFieldPathExpression ::= IdentificationVariable "." StateField | SingleValuedAssociationPathExpression "." StateField - * SingleValuedAssociationPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* SingleValuedAssociationField - * CollectionValuedPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* CollectionValuedAssociationField + * StateFieldPathExpression ::= IdentificationVariable "." StateField + * SingleValuedAssociationPathExpression ::= IdentificationVariable "." SingleValuedAssociationField + * CollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField * * @param array $deferredItem * @param mixed $AST @@ -561,93 +563,31 @@ private function _processDeferredPathExpressions($AST) $pathExpression = $deferredItem['expression']; $qComp = $this->_queryComponents[$pathExpression->identificationVariable]; - $numParts = count($pathExpression->parts); + $class = $qComp['metadata']; - if ($numParts == 0) { - $pathExpression->parts = array($qComp['metadata']->identifier[0]); - $numParts++; + if (($field = $pathExpression->field) === null) { + $field = $pathExpression->field = $class->identifier[0]; } - $parts = $pathExpression->parts; - $aliasIdentificationVariable = $pathExpression->identificationVariable; - $parentField = $pathExpression->identificationVariable; - $class = $qComp['metadata']; - $fieldType = null; - $curIndex = 0; - - foreach ($parts as $field) { - // Check if it is not in a state field - if ($fieldType & AST\PathExpression::TYPE_STATE_FIELD) { - $this->semanticalError( - 'Cannot navigate through state field named ' . $field . ' on ' . $parentField, - $deferredItem['token'] - ); - } - - // Check if it is not a collection field - if ($fieldType & AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION) { - $this->semanticalError( - 'Cannot navigate through collection field named ' . $field . ' on ' . $parentField, - $deferredItem['token'] - ); - } - - // Check if field or association exists - if ( ! isset($class->associationMappings[$field]) && ! isset($class->fieldMappings[$field])) { - $this->semanticalError( - 'Class ' . $class->name . ' has no field or association named ' . $field, - $deferredItem['token'] - ); - } + // Check if field or association exists + if ( ! isset($class->associationMappings[$field]) && ! isset($class->fieldMappings[$field])) { + $this->semanticalError( + 'Class ' . $class->name . ' has no field or association named ' . $field, + $deferredItem['token'] + ); + } - $parentField = $field; + if (isset($class->fieldMappings[$field])) { + $fieldType = AST\PathExpression::TYPE_STATE_FIELD; + } else { + $assoc = $class->associationMappings[$field]; + $class = $this->_em->getClassMetadata($assoc->targetEntityName); - if (isset($class->fieldMappings[$field])) { - $fieldType = AST\PathExpression::TYPE_STATE_FIELD; + if ($assoc->isOneToOne()) { + $fieldType = AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; } else { - $assoc = $class->associationMappings[$field]; - $class = $this->_em->getClassMetadata($assoc->targetEntityName); - - if ( - ($curIndex != $numParts - 1) && - ! isset($this->_queryComponents[$aliasIdentificationVariable . '.' . $field]) - ) { - // Building queryComponent - $joinQueryComponent = array( - 'metadata' => $class, - 'parent' => $aliasIdentificationVariable, - 'relation' => $assoc, - 'map' => null, - 'nestingLevel' => $this->_nestingLevel, - 'token' => $deferredItem['token'], - ); - - // Create AST node - $joinVariableDeclaration = new AST\JoinVariableDeclaration( - new AST\Join( - AST\Join::JOIN_TYPE_INNER, - new AST\JoinAssociationPathExpression($aliasIdentificationVariable, $field), - $aliasIdentificationVariable . '.' . $field, - false - ), - null - ); - - $AST->fromClause->identificationVariableDeclarations[0]->joinVariableDeclarations[] = $joinVariableDeclaration; - - $this->_queryComponents[$aliasIdentificationVariable . '.' . $field] = $joinQueryComponent; - } - - $aliasIdentificationVariable .= '.' . $field; - - if ($assoc->isOneToOne()) { - $fieldType = AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; - } else { - $fieldType = AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION; - } + $fieldType = AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION; } - - ++$curIndex; } // Validate if PathExpression is one of the expected types @@ -683,7 +623,7 @@ private function _processDeferredPathExpressions($AST) $this->semanticalError($semanticalError, $deferredItem['token']); } - + // We need to force the type in PathExpression $pathExpression->type = $fieldType; } @@ -891,11 +831,11 @@ public function ResultVariable() public function JoinAssociationPathExpression() { $token = $this->_lexer->lookahead; - $identVariable = $this->IdentificationVariable(); + $this->match(Lexer::T_DOT); $this->match(Lexer::T_IDENTIFIER); - //$this->match($this->_lexer->lookahead['type']); + $field = $this->_lexer->token['value']; // Validate association field @@ -913,7 +853,7 @@ public function JoinAssociationPathExpression() * Parses an arbitrary path expression and defers semantical validation * based on expected types. * - * PathExpression ::= IdentificationVariable {"." identifier}* "." identifier + * PathExpression ::= IdentificationVariable "." identifier * * @param integer $expectedTypes * @return \Doctrine\ORM\Query\AST\PathExpression @@ -922,17 +862,17 @@ public function PathExpression($expectedTypes) { $token = $this->_lexer->lookahead; $identVariable = $this->IdentificationVariable(); - $parts = array(); + $field = null; - while ($this->_lexer->isNextToken(Lexer::T_DOT)) { + if ($this->_lexer->isNextToken(Lexer::T_DOT)) { $this->match(Lexer::T_DOT); $this->match(Lexer::T_IDENTIFIER); - $parts[] = $this->_lexer->token['value']; + $field = $this->_lexer->token['value']; } - + // Creating AST node - $pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $parts); + $pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $field); // Defer PathExpression validation if requested to be defered $this->_deferredPathExpressions[] = array( @@ -971,7 +911,7 @@ public function SingleValuedPathExpression() } /** - * StateFieldPathExpression ::= SimpleStateFieldPathExpression | SimpleStateFieldAssociationPathExpression + * StateFieldPathExpression ::= IdentificationVariable "." StateField * * @return \Doctrine\ORM\Query\AST\PathExpression */ @@ -981,7 +921,7 @@ public function StateFieldPathExpression() } /** - * SingleValuedAssociationPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* SingleValuedAssociationField + * SingleValuedAssociationPathExpression ::= IdentificationVariable "." SingleValuedAssociationField * * @return \Doctrine\ORM\Query\AST\PathExpression */ @@ -991,7 +931,7 @@ public function SingleValuedAssociationPathExpression() } /** - * CollectionValuedPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* CollectionValuedAssociationField + * CollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField * * @return \Doctrine\ORM\Query\AST\PathExpression */ @@ -1000,26 +940,6 @@ public function CollectionValuedPathExpression() return $this->PathExpression(AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION); } - /** - * SimpleStateFieldPathExpression ::= IdentificationVariable "." StateField - * - * @return \Doctrine\ORM\Query\AST\PathExpression - */ - public function SimpleStateFieldPathExpression() - { - $pathExpression = $this->PathExpression(AST\PathExpression::TYPE_STATE_FIELD); - $parts = $pathExpression->parts; - - if (count($parts) > 1) { - $this->semanticalError( - "Invalid SimpleStateFieldPathExpression. " . - "Expected state field, got association '{$parts[0]}'." - ); - } - - return $pathExpression; - } - /** * SelectClause ::= "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression} * @@ -1292,7 +1212,9 @@ public function Subselect() public function UpdateItem() { $pathExpr = $this->PathExpression(AST\PathExpression::TYPE_STATE_FIELD | AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION); + $this->match(Lexer::T_EQUALS); + $updateItem = new AST\UpdateItem($pathExpr, $this->NewValue()); return $updateItem; @@ -1308,7 +1230,7 @@ public function GroupByItem() // We need to check if we are in a IdentificationVariable or SingleValuedPathExpression $glimpse = $this->_lexer->glimpse(); - if ($glimpse['value'] != '.') { + if ($glimpse['type'] != Lexer::T_DOT) { $token = $this->_lexer->lookahead; $identVariable = $this->IdentificationVariable(); @@ -1333,7 +1255,7 @@ public function OrderByItem() // We need to check if we are in a ResultVariable or StateFieldPathExpression $glimpse = $this->_lexer->glimpse(); - if ($glimpse['value'] != '.') { + if ($glimpse['type'] != Lexer::T_DOT) { $token = $this->_lexer->lookahead; $expr = $this->ResultVariable(); } else { @@ -1409,9 +1331,11 @@ public function IdentificationVariableDeclaration() */ public function SubselectIdentificationVariableDeclaration() { - $peek = $this->_lexer->glimpse(); + $glimpse = $this->_lexer->glimpse(); + + /* NOT YET IMPLEMENTED! - if ($peek['value'] == '.') { + if ($glimpse['type'] == Lexer::T_DOT) { $subselectIdVarDecl = new AST\SubselectIdentificationVariableDeclaration(); $subselectIdVarDecl->associationPathExpression = $this->AssociationPathExpression(); $this->match(Lexer::T_AS); @@ -1419,6 +1343,7 @@ public function SubselectIdentificationVariableDeclaration() return $subselectIdVarDecl; } + */ return $this->IdentificationVariableDeclaration(); } @@ -1486,11 +1411,13 @@ public function PartialObjectExpression() $this->match(Lexer::T_OPEN_CURLY_BRACE); $this->match(Lexer::T_IDENTIFIER); $partialFieldSet[] = $this->_lexer->token['value']; + while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $this->match(Lexer::T_IDENTIFIER); $partialFieldSet[] = $this->_lexer->token['value']; } + $this->match(Lexer::T_CLOSE_CURLY_BRACE); $partialObjectExpression = new AST\PartialObjectExpression($identificationVariable, $partialFieldSet); @@ -1577,7 +1504,7 @@ public function Join() } /** - * IndexBy ::= "INDEX" "BY" SimpleStateFieldPathExpression + * IndexBy ::= "INDEX" "BY" StateFieldPathExpression * * @return Doctrine\ORM\Query\AST\IndexBy */ @@ -1585,13 +1512,12 @@ public function IndexBy() { $this->match(Lexer::T_INDEX); $this->match(Lexer::T_BY); - $pathExp = $this->SimpleStateFieldPathExpression(); + $pathExpr = $this->StateFieldPathExpression(); // Add the INDEX BY info to the query component - $parts = $pathExp->parts; - $this->_queryComponents[$pathExp->identificationVariable]['map'] = $parts[0]; + $this->_queryComponents[$pathExpr->identificationVariable]['map'] = $pathExpr->field; - return new AST\IndexBy($pathExp); + return new AST\IndexBy($pathExpr); } /** @@ -1725,9 +1651,9 @@ public function SimpleSelectExpression() { if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) { // SingleValuedPathExpression | IdentificationVariable - $peek = $this->_lexer->glimpse(); + $glimpse = $this->_lexer->glimpse(); - if ($peek['value'] == '.') { + if ($glimpse['type'] == Lexer::T_DOT) { return new AST\SimpleSelectExpression($this->StateFieldPathExpression()); } @@ -2199,7 +2125,7 @@ public function ArithmeticPrimary() return $this->SingleValuedPathExpression(); } - return $this->SimpleStateFieldPathExpression(); + return $this->StateFieldPathExpression(); case Lexer::T_INPUT_PARAMETER: return $this->InputParameter(); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 786384a1ac9..4f5c2332522 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -438,7 +438,7 @@ public function walkDeleteStatement(AST\DeleteStatement $AST) * @param string $identificationVariable * @return string The SQL. */ - public function walkIdentificationVariable($identificationVariable, $fieldName = null) + public function walkIdentificationVariable($identificationVariable, $fieldName) { $class = $this->_queryComponents[$identificationVariable]['metadata']; @@ -464,9 +464,8 @@ public function walkPathExpression($pathExpr) switch ($pathExpr->type) { case AST\PathExpression::TYPE_STATE_FIELD: - $parts = $pathExpr->parts; - $fieldName = array_pop($parts); - $dqlAlias = $pathExpr->identificationVariable . ( ! empty($parts) ? '.' . implode('.', $parts) : ''); + $fieldName = $pathExpr->field; + $dqlAlias = $pathExpr->identificationVariable; $class = $this->_queryComponents[$dqlAlias]['metadata']; if ($this->_useSqlTableAliases) { @@ -479,8 +478,7 @@ public function walkPathExpression($pathExpr) case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION: // 1- the owning side: // Just use the foreign key, i.e. u.group_id - $parts = $pathExpr->parts; - $fieldName = array_pop($parts); + $fieldName = $pathExpr->field; $dqlAlias = $pathExpr->identificationVariable; $class = $this->_queryComponents[$dqlAlias]['metadata']; @@ -630,7 +628,7 @@ public function walkFromClause($fromClause) if ($identificationVariableDecl->indexBy) { $this->_rsm->addIndexBy( $identificationVariableDecl->indexBy->simpleStateFieldPathExpression->identificationVariable, - $identificationVariableDecl->indexBy->simpleStateFieldPathExpression->parts[0] + $identificationVariableDecl->indexBy->simpleStateFieldPathExpression->field ); } @@ -840,9 +838,8 @@ public function walkSelectExpression($selectExpression) if ($expr instanceof AST\PathExpression) { if ($expr->type == AST\PathExpression::TYPE_STATE_FIELD) { - $parts = $expr->parts; - $fieldName = array_pop($parts); - $dqlAlias = $expr->identificationVariable . (( ! empty($parts)) ? '.' . implode('.', $parts) : ''); + $fieldName = $expr->field; + $dqlAlias = $expr->identificationVariable; $qComp = $this->_queryComponents[$dqlAlias]; $class = $qComp['metadata']; @@ -1345,9 +1342,8 @@ public function walkCollectionMemberExpression($collMemberExpr) $entityExpr = $collMemberExpr->entityExpression; $collPathExpr = $collMemberExpr->collectionValuedPathExpression; - $parts = $collPathExpr->parts; - $fieldName = array_pop($parts); - $dqlAlias = $collPathExpr->identificationVariable . (( ! empty($parts)) ? '.' . implode('.', $parts) : ''); + $fieldName = $collPathExpr->field; + $dqlAlias = $collPathExpr->identificationVariable; $class = $this->_queryComponents[$dqlAlias]['metadata']; diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php index 6a994c9442b..e7bb831081d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php @@ -92,7 +92,7 @@ public function testIsNullAssocation() public function testSelectSubselect() { - $dql = 'SELECT p, (SELECT c.brand FROM Doctrine\Tests\Models\Company\CompanyCar c WHERE p.car.id = c.id) brandName '. + $dql = 'SELECT p, (SELECT c.brand FROM Doctrine\Tests\Models\Company\CompanyCar c WHERE p.car = c) brandName '. 'FROM Doctrine\Tests\Models\Company\CompanyManager p'; $result = $this->_em->createQuery($dql)->getArrayResult(); diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php index d7c7a4259f9..c295af47852 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php @@ -47,14 +47,23 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed) $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\Tests\ORM\Functional\CustomTreeWalker')) ->useQueryCache(false); - parent::assertEquals($sqlToBeConfirmed, $query->getSql()); + $this->assertEquals($sqlToBeConfirmed, $query->getSql()); $query->free(); } catch (\Exception $e) { - $this->fail($e->getMessage()); + $this->fail($e->getMessage() . ' at "' . $e->getFile() . '" on line ' . $e->getLine()); + } } public function testSupportsQueriesWithoutWhere() + { + $this->assertSqlGeneration( + 'select u from Doctrine\Tests\Models\CMS\CmsUser u', + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id = 1" + ); + } + + public function testSupportsQueriesWithMultipleConditionalExpressions() { $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name or u.name = :otherName', @@ -62,21 +71,13 @@ public function testSupportsQueriesWithoutWhere() ); } - public function testSupportsQueriesWithSimpleConditionalExpressions() + public function testSupportsQueriesWithSimpleConditionalExpression() { $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name', "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.name = ? AND c0_.id = 1" ); } - - public function testSupportsQueriesWithMultipleConditionalExpressions() - { - $this->assertSqlGeneration( - 'select u from Doctrine\Tests\Models\CMS\CmsUser u', - "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id = 1" - ); - } } class CustomTreeWalker extends Query\TreeWalkerAdapter @@ -97,7 +98,7 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) // Create our conditions for all involved classes $factors = array(); foreach ($dqlAliases as $alias) { - $pathExpr = new Query\AST\PathExpression(Query\AST\PathExpression::TYPE_STATE_FIELD, $alias, array('id')); + $pathExpr = new Query\AST\PathExpression(Query\AST\PathExpression::TYPE_STATE_FIELD, $alias, 'id'); $pathExpr->type = Query\AST\PathExpression::TYPE_STATE_FIELD; $comparisonExpr = new Query\AST\ComparisonExpression($pathExpr, '=', 1); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php index 5503d033eba..25f378255a9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php @@ -17,7 +17,7 @@ protected function setUp() public function testIssue() { - $q = $this->_em->createQuery("select u, u.contact.data from ".__NAMESPACE__."\\DDC493Distributor u"); + $q = $this->_em->createQuery("select u, c.data from ".__NAMESPACE__."\\DDC493Distributor u JOIN u.contact c"); $this->assertEquals('SELECT d0_.id AS id0, d1_.data AS data1, d0_.discr AS discr2, d0_.contact AS contact3 FROM DDC493Distributor d2_ INNER JOIN DDC493Customer d0_ ON d2_.id = d0_.id INNER JOIN DDC493Contact d1_ ON d0_.contact = d1_.id', $q->getSQL()); } } diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index 23640142f4a..26e7cd0ba23 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -89,11 +89,6 @@ public function testSelectMultipleComponentsWithAsterisk() $this->assertValidDql('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p'); } - public function testSelectMultipleComponentsWithAsterisk2() - { - $this->assertValidDql('SELECT a.user.name FROM Doctrine\Tests\Models\CMS\CmsArticle a'); - } - public function testSelectDistinctIsSupported() { $this->assertValidDql('SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u'); @@ -294,13 +289,13 @@ public function testImplicitJoinInWhereOnSingleValuedAssociationPathExpression() { // This should be allowed because avatar is a single-value association. // SQL: SELECT ... FROM forum_user fu INNER JOIN forum_avatar fa ON fu.avatar_id = fa.id WHERE fa.id = ? - $this->assertValidDql("SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.avatar.id = ?1"); + $this->assertValidDql("SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a WHERE a.id = ?1"); } public function testImplicitJoinInWhereOnCollectionValuedPathExpression() { // This should be forbidden, because articles is a collection - $this->assertInvalidDql("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.articles.title = ?"); + $this->assertInvalidDql("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a WHERE a.title = ?"); } public function testInvalidSyntaxIsRejected() diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 97cf04985cf..35a51a42efb 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -51,7 +51,7 @@ public function testSupportsSelectForOneField() public function testSupportsSelectForOneNestedField() { $this->assertSqlGeneration( - 'SELECT a.user.id FROM Doctrine\Tests\Models\CMS\CmsArticle a', + 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsArticle a JOIN a.user u', 'SELECT c0_.id AS id0 FROM cms_articles c1_ INNER JOIN cms_users c0_ ON c1_.user_id = c0_.id' ); } @@ -59,7 +59,7 @@ public function testSupportsSelectForOneNestedField() public function testSupportsSelectForAllNestedField() { $this->assertSqlGeneration( - 'SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a ORDER BY a.user.name ASC', + 'SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a JOIN a.user u ORDER BY u.name ASC', 'SELECT c0_.id AS id0, c0_.topic AS topic1, c0_.text AS text2, c0_.version AS version3 FROM cms_articles c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id ORDER BY c1_.name ASC' ); }