Compare commits

...

25 Commits
2.0.3 ... 2.0.4

Author SHA1 Message Date
Benjamin Eberlei
8a2b1058c3 Release 2.0.4 2011-04-07 15:03:49 -04:00
Benjamin Eberlei
2bdceefb2d Bump dependencies, Doctrine Common to 2.0.2 and DBAL to 2.0.4 2011-04-07 20:53:19 +02:00
Benjamin Eberlei
71bcdce031 Merge branch 'DDC-1040' into 2.0.x 2011-04-03 23:08:24 +02:00
Benjamin Eberlei
f6a700062d [DDC-1040] Bugfix with named parameters and multiple entities passed as parameter. 2011-04-03 23:08:07 +02:00
Benjamin Eberlei
fb4db2782c [DDC-1040] Add regression tests for entity as multiple named/positional parameters. 2011-04-03 23:06:47 +02:00
Benjamin Eberlei
39ec8de08b Merge branch 'DDC-1093' into 2.0.x 2011-04-03 20:29:41 +02:00
Benjamin Eberlei
7a469581e1 [DDC-1093] Fix docblock type hint 2011-04-03 20:29:32 +02:00
Benjamin Eberlei
1f8cdb77be Merge branch 'DDC-1087' into 2.0.x 2011-04-03 09:12:10 +02:00
Benjamin Eberlei
af5bcc148d [DDC-1087] Add missing resolution to IS NULL in EntityRepository when passing a null value as a criteria. 2011-04-03 09:11:54 +02:00
Benjamin Eberlei
06870fd87f Merge branch 'DDC-1077' into 2.0.x 2011-03-27 21:12:24 +02:00
Benjamin Eberlei
26af92f452 [DDC-1077] Bugfix in not handling literals in Select Expressions. 2011-03-27 21:12:05 +02:00
Benjamin Eberlei
97d97a8a89 Merge branch 'DDC-1079' into 2.0.x 2011-03-27 14:06:05 +02:00
Benjamin Eberlei
3df673cb6a [DDC-1079] Bugfix for shortcut for ArithmeticExpressions in SimpleSelectExpression that lead to literals not being valid. Problem was that ScalarExpression() did not handle AggregateExpressions() at all, which is now fixed. 2011-03-27 14:05:33 +02:00
Benjamin Eberlei
1c05831b20 Merge ModifyLimitQueryFix into 2.0.x 2011-03-20 16:06:36 -04:00
Benjamin Eberlei
26126a10cd Bump Dev Version to 2.0.4-DEV 2011-03-20 16:04:07 -04:00
Benjamin Eberlei
3d406afa38 Merge branch 'DDC-992' into 2.0.x 2011-03-20 17:14:17 +01:00
Benjamin Eberlei
526f21ad3d [DDC-992] Fix criteria usage of column names clashing with field or associations by prefixing with table names or alias. 2011-03-20 17:14:04 +01:00
Benjamin Eberlei
31722cf8f6 [DDC-1053] Fix rebase/merge mistake in tests. 2011-03-20 14:10:33 +01:00
Benjamin Eberlei
758a09dfe8 Merge branch 'DDC-1053' into 2.0.x 2011-03-20 14:09:15 +01:00
Benjamin Eberlei
ba00dd13b6 [DDC-1053] Fix bug with usage of identification variables in GroupByItem. 2011-03-20 14:08:57 +01:00
Benjamin Eberlei
ff65aeed60 Merge branch 'DDC-1052' into 2.0.x 2011-03-20 13:08:48 +01:00
Benjamin Eberlei
3a5d70fbf3 [DDC-1052] Fix bug with versioning and inheritance 2011-03-20 13:08:16 +01:00
Benjamin Eberlei
68257a8c93 Merge branch 'DDC-1070' into 2.0.x 2011-03-20 12:23:43 +01:00
Benjamin Eberlei
3b4596691f [DDC-1070] Fix in AbstractQuery::iterate() method not respecting hydrator and parameters. 2011-03-20 12:23:21 +01:00
Benjamin Eberlei
ecb409412f Bump Dev Version to 2.0.3-DEV 2011-03-05 04:12:43 -05:00
17 changed files with 467 additions and 41 deletions

View File

@@ -476,10 +476,20 @@ abstract class AbstractQuery
* @param integer $hydrationMode The hydration mode to use.
* @return IterableResult
*/
public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT)
public function iterate(array $params = array(), $hydrationMode = null)
{
if ($hydrationMode !== null) {
$this->setHydrationMode($hydrationMode);
}
if ($params) {
$this->setParameters($params);
}
$stmt = $this->_doExecute();
return $this->_em->newHydrator($this->_hydrationMode)->iterate(
$this->_doExecute($params, $hydrationMode), $this->_resultSetMapping, $this->_hints
$stmt, $this->_resultSetMapping, $this->_hints
);
}

View File

@@ -96,12 +96,16 @@ class EntityManager
private $proxyFactory;
/**
* @var ExpressionBuilder The expression builder instance used to generate query expressions.
* The expression builder instance used to generate query expressions.
*
* @var Doctrine\ORM\Query\Expr
*/
private $expressionBuilder;
/**
* Whether the EntityManager is closed or not.
*
* @var bool
*/
private $closed = false;
@@ -163,7 +167,7 @@ class EntityManager
* ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));
* </code>
*
* @return ExpressionBuilder
* @return Doctrine\ORM\Query\Expr
*/
public function getExpressionBuilder()
{

View File

@@ -358,7 +358,7 @@ class BasicEntityPersister
$result = $this->_conn->executeUpdate($sql, $params, $types);
if ($this->_class->isVersioned && ! $result) {
if ($versioned && ! $result) {
throw OptimisticLockException::lockFailed($entity);
}
}
@@ -750,9 +750,10 @@ class BasicEntityPersister
$sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']);
$joinTableConditions = array();
if ($assoc['isOwningSide']) {
$quotedJoinTable = $sourceClass->getQuotedJoinTableName($assoc, $this->_platform);
foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) {
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
$criteria[$quotedJoinTable . "." . $relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
@@ -761,10 +762,11 @@ class BasicEntityPersister
}
} else {
$owningAssoc = $this->_em->getClassMetadata($assoc['targetEntity'])->associationMappings[$assoc['mappedBy']];
$quotedJoinTable = $sourceClass->getQuotedJoinTableName($owningAssoc, $this->_platform);
// TRICKY: since the association is inverted source and target are flipped
foreach ($owningAssoc['relationToTargetKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) {
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
$criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
$criteria[$quotedJoinTable . "." . $relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
} else {
throw MappingException::joinColumnMustPointToMappedField(
$sourceClass->name, $sourceKeyColumn
@@ -1169,18 +1171,16 @@ class BasicEntityPersister
$conditionSql .= $this->_class->associationMappings[$field]['joinColumns'][0]['name'];
} else if ($assoc !== null) {
if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) {
$owningAssoc = $assoc['isOwningSide'] ? $assoc : $this->_em->getClassMetadata($assoc['targetEntity'])
->associationMappings[$assoc['mappedBy']];
$conditionSql .= $this->_class->getQuotedJoinTableName($owningAssoc, $this->_platform) . '.' . $field;
} else {
$conditionSql .= $field;
}
} else if ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false) {
// very careless developers could potentially open up this normally hidden api for userland attacks,
// therefore checking for spaces and function calls which are not allowed.
// found a join column condition, not really a "field"
$conditionSql .= $field;
} else {
throw ORMException::unrecognizedField($field);
}
$conditionSql .= ' = ?';
$conditionSql .= ($value === null) ? ' IS NULL' : ' = ?';
}
return $conditionSql;
}
@@ -1197,8 +1197,13 @@ class BasicEntityPersister
$criteria = array();
$owningAssoc = $this->_class->associationMappings[$assoc['mappedBy']];
$sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']);
$tableAlias = isset($owningAssoc['inherited']) ?
$this->_getSQLTableAlias($owningAssoc['inherited'])
: $this->_getSQLTableAlias($this->_class->name);
foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) {
$criteria[$targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
$criteria[$tableAlias . "." . $targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
}
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
@@ -1221,6 +1226,10 @@ class BasicEntityPersister
$params = $types = array();
foreach ($criteria AS $field => $value) {
if ($value === null) {
continue; // skip null values.
}
$type = null;
if (isset($this->_class->fieldMappings[$field])) {
$type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType();

View File

@@ -249,7 +249,12 @@ final class Query extends AbstractQuery
$idValues = $class->getIdentifierValues($value);
}
$sqlPositions = $paramMappings[$key];
$sqlParams += array_combine((array)$sqlPositions, $idValues);
$cSqlPos = count($sqlPositions);
$cIdValues = count($idValues);
$idValues = array_values($idValues);
for ($i = 0; $i < $cSqlPos; $i++) {
$sqlParams[$sqlPositions[$i]] = $idValues[ ($i % $cIdValues) ];
}
} else {
foreach ($paramMappings[$key] as $position) {
$sqlParams[$position] = $value;

View File

@@ -1324,6 +1324,10 @@ class Parser
$token = $this->_lexer->lookahead;
$identVariable = $this->IdentificationVariable();
if (!isset($this->_queryComponents[$identVariable])) {
$this->semanticalError('Cannot group by undefined identification variable.');
}
return $identVariable;
}
@@ -1633,7 +1637,7 @@ class Parser
return $this->StateFieldPathExpression();
} else if ($lookahead == Lexer::T_INTEGER || $lookahead == Lexer::T_FLOAT) {
return $this->SimpleArithmeticExpression();
} else if ($this->_isFunction()) {
} else if ($this->_isFunction() || $this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
// We may be in an ArithmeticExpression (find the matching ")" and inspect for Math operator)
$this->_lexer->peek(); // "("
$peek = $this->_peekBeyondClosingParenthesis();
@@ -1641,8 +1645,12 @@ class Parser
if ($this->_isMathOperator($peek)) {
return $this->SimpleArithmeticExpression();
}
return $this->FunctionDeclaration();
if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
return $this->AggregateExpression();
} else {
return $this->FunctionDeclaration();
}
} else if ($lookahead == Lexer::T_STRING) {
return $this->StringPrimary();
} else if ($lookahead == Lexer::T_INPUT_PARAMETER) {
@@ -1717,7 +1725,8 @@ class Parser
$expression = $this->PartialObjectExpression();
$identVariable = $expression->identificationVariable;
} else if ($this->_lexer->lookahead['type'] == Lexer::T_INTEGER ||
$this->_lexer->lookahead['type'] == Lexer::T_FLOAT) {
$this->_lexer->lookahead['type'] == Lexer::T_FLOAT ||
$this->_lexer->lookahead['type'] == Lexer::T_STRING) {
// Shortcut: ScalarExpression => SimpleArithmeticExpression
$expression = $this->SimpleArithmeticExpression();
} else {
@@ -1786,15 +1795,8 @@ class Parser
}
$this->_lexer->peek();
$beyond = $this->_peekBeyondClosingParenthesis();
if ($this->_isMathOperator($beyond)) {
$expression = $this->ScalarExpression();
} else if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
$expression = $this->AggregateExpression();
} else {
$expression = $this->FunctionDeclaration();
}
$expression = $this->ScalarExpression();
$expr = new AST\SimpleSelectExpression($expression);

View File

@@ -75,8 +75,7 @@ class QueryException extends \Doctrine\ORM\ORMException
public static function invalidPathExpression($pathExpr)
{
return new self(
"Invalid PathExpression '" . $pathExpr->identificationVariable .
"." . implode('.', $pathExpr->parts) . "'."
"Invalid PathExpression '" . $pathExpr->identificationVariable . "." . $pathExpr->field . "'."
);
}

View File

@@ -927,7 +927,8 @@ class SqlWalker implements TreeWalker
$expr instanceof AST\SimpleArithmeticExpression ||
$expr instanceof AST\ArithmeticTerm ||
$expr instanceof AST\ArithmeticFactor ||
$expr instanceof AST\ArithmeticPrimary
$expr instanceof AST\ArithmeticPrimary ||
$expr instanceof AST\Literal
) {
if ( ! $selectExpression->fieldIdentificationVariable) {
$resultAlias = $this->_scalarResultCounter++;
@@ -936,7 +937,11 @@ class SqlWalker implements TreeWalker
}
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias;
if ($expr instanceof AST\Literal) {
$sql .= $this->walkLiteral($expr) . ' AS ' .$columnAlias;
} else {
$sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias;
}
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
@@ -1197,9 +1202,25 @@ class SqlWalker implements TreeWalker
*/
public function walkGroupByClause($groupByClause)
{
return ' GROUP BY ' . implode(
', ', array_map(array($this, 'walkGroupByItem'), $groupByClause->groupByItems)
);
$sql = '';
foreach ($groupByClause->groupByItems AS $groupByItem) {
if (is_string($groupByItem)) {
foreach ($this->_queryComponents[$groupByItem]['metadata']->identifier AS $idField) {
if ($sql != '') {
$sql .= ', ';
}
$groupByItem = new AST\PathExpression(AST\PathExpression::TYPE_STATE_FIELD, $groupByItem, $idField);
$groupByItem->type = AST\PathExpression::TYPE_STATE_FIELD;
$sql .= $this->walkGroupByItem($groupByItem);
}
} else {
if ($sql != '') {
$sql .= ', ';
}
$sql .= $this->walkGroupByItem($groupByItem);
}
}
return ' GROUP BY ' . $sql;
}
/**

View File

@@ -36,7 +36,7 @@ class Version
/**
* Current Doctrine Version
*/
const VERSION = '2.0.3';
const VERSION = '2.0.4';
/**
* Compares a Doctrine version with the current one.

View File

@@ -410,4 +410,29 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId());
$this->assertType('Doctrine\ORM\Proxy\Proxy', $ref, "A proxy can be generated only if no subclasses exists for the requested reference.");
}
/**
* @group DDC-992
*/
public function testGetSubClassManyToManyCollection()
{
$manager = new CompanyManager();
$manager->setName('gblanco');
$manager->setSalary(1234);
$manager->setTitle('Awesome!');
$manager->setDepartment('IT');
$person = new CompanyPerson();
$person->setName('friend');
$manager->addFriend($person);
$this->_em->persist($manager);
$this->_em->persist($person);
$this->_em->flush();
$this->_em->clear();
$manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId());
$this->assertEquals(1, count($manager->getFriends()));
}
}

View File

@@ -290,5 +290,17 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertType('Doctrine\Tests\Models\CMS\CmsAddress', $address);
$this->assertEquals($addressId, $address->id);
}
/**
* @group DDC-1087
*/
public function testIsNullCriteria()
{
$repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repos->findBy(array('status' => null, 'username' => 'romanb'));
$params = $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['params'];
$this->assertEquals(1, count($params), "Should only execute with one parameter.");
$this->assertEquals(array('romanb'), $params);
}
}

View File

@@ -4,6 +4,8 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\Models\CMS\CmsUser,
Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
@@ -135,6 +137,39 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$users = $q->getResult();
}
/**
* @group DDC-1070
*/
public function testIterateResultAsArrayAndParams()
{
$article1 = new CmsArticle;
$article1->topic = "Doctrine 2";
$article1->text = "This is an introduction to Doctrine 2.";
$article2 = new CmsArticle;
$article2->topic = "Symfony 2";
$article2->text = "This is an introduction to Symfony 2.";
$this->_em->persist($article1);
$this->_em->persist($article2);
$this->_em->flush();
$this->_em->clear();
$articleId = $article1->id;
$query = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1");
$articles = $query->iterate(array(1 => 'Doctrine 2'), Query::HYDRATE_ARRAY);
$found = array();
foreach ($articles AS $article) {
$found[] = $article;
}
$this->assertEquals(1, count($found));
$this->assertEquals(array(
array(array('id' => $articleId, 'topic' => 'Doctrine 2', 'text' => 'This is an introduction to Doctrine 2.', 'version' => 1))
), $found);
}
public function testIterateResult_IterativelyBuildUpUnitOfWork()
{
$article1 = new CmsArticle;

View File

@@ -0,0 +1,83 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsUser;
require_once __DIR__ . '/../../../TestInit.php';
/**
* @group DDC-1040
*/
class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testReuseNamedEntityParameter()
{
$user = new CmsUser();
$user->name = "John Galt";
$user->username = "jgalt";
$user->status = "inactive";
$article = new CmsArticle();
$article->topic = "This is John Galt speaking!";
$article->text = "Yadda Yadda!";
$article->setAuthor($user);
$this->_em->persist($user);
$this->_em->persist($article);
$this->_em->flush();
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = :author";
$this->_em->createQuery($dql)
->setParameter('author', $user)
->getResult();
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = :author AND a.user = :author";
$this->_em->createQuery($dql)
->setParameter('author', $user)
->getResult();
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = :topic AND a.user = :author AND a.user = :author AND a.text = :text";
$farticle = $this->_em->createQuery($dql)
->setParameter('author', $user)
->setParameter('topic', 'This is John Galt speaking!')
->setParameter('text', 'Yadda Yadda!')
->getSingleResult();
$this->assertSame($article, $farticle);
}
public function testUseMultiplePositionalParameters()
{
$user = new CmsUser();
$user->name = "John Galt";
$user->username = "jgalt";
$user->status = "inactive";
$article = new CmsArticle();
$article->topic = "This is John Galt speaking!";
$article->text = "Yadda Yadda!";
$article->setAuthor($user);
$this->_em->persist($user);
$this->_em->persist($article);
$this->_em->flush();
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1 AND a.user = ?2 AND a.user = ?3 AND a.text = ?4";
$farticle = $this->_em->createQuery($dql)
->setParameter(1, 'This is John Galt speaking!')
->setParameter(2, $user)
->setParameter(3, $user)
->setParameter(4, 'Yadda Yadda!')
->getSingleResult();
$this->assertSame($article, $farticle);
}
}

View File

@@ -0,0 +1,147 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
require_once __DIR__ . '/../../../TestInit.php';
/**
* @group DDC-992
*/
class DDC992Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
parent::setUp();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Role'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Parent'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Child'),
));
} catch(\Exception $e) {
}
}
public function testIssue()
{
$role = new DDC992Role();
$role->name = "Parent";
$child = new DDC992Role();
$child->name = "child";
$role->extendedBy[] = $child;
$child->extends[] = $role;
$this->_em->persist($role);
$this->_em->persist($child);
$this->_em->flush();
$this->_em->clear();
$child = $this->_em->getRepository(get_class($role))->find($child->roleID);
$parents = count($child->extends);
$this->assertEquals(1, $parents);
foreach ($child->extends AS $parent) {
$this->assertEquals($role->getRoleID(), $parent->getRoleID());
}
}
public function testOneToManyChild()
{
$parent = new DDC992Parent();
$child = new DDC992Child();
$child->parent = $parent;
$parent->childs[] = $child;
$this->_em->persist($parent);
$this->_em->persist($child);
$this->_em->flush();
$this->_em->clear();
$parentRepository = $this->_em->getRepository(get_class($parent));
$childRepository = $this->_em->getRepository(get_class($child));
$parent = $parentRepository->find($parent->id);
$this->assertEquals(1, count($parent->childs));
$this->assertEquals(0, count($parent->childs[0]->childs()));
$child = $parentRepository->findOneBy(array("id" => $child->id));
$this->assertSame($parent->childs[0], $child);
$this->_em->clear();
$child = $parentRepository->find($child->id);
$this->assertEquals(0, count($child->childs));
$this->_em->clear();
$child = $childRepository->find($child->id);
$this->assertEquals(0, count($child->childs));
}
}
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorMap({"child" = "DDC992Child", "parent" = "DDC992Parent"})
*/
class DDC992Parent
{
/** @Id @GeneratedValue @Column(type="integer") */
public $id;
/** @ManyToOne(targetEntity="DDC992Parent", inversedBy="childs") */
public $parent;
/** @OneToMany(targetEntity="DDC992Child", mappedBy="parent") */
public $childs;
}
/**
* @Entity
*/
class DDC992Child extends DDC992Parent
{
public function childs()
{
return $this->childs;
}
}
/**
* @Entity
*/
class DDC992Role
{
public function getRoleID()
{
return $this->roleID;
}
/**
* @Id @Column(name="roleID", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $roleID;
/**
* @Column (name="name", type="string", length="45")
*/
public $name;
/**
* @ManyToMany (targetEntity="DDC992Role", mappedBy="extends")
*/
public $extendedBy;
/**
* @ManyToMany (targetEntity="DDC992Role", inversedBy="extendedBy")
* @JoinTable (name="RoleRelations",
* joinColumns={@JoinColumn(name="roleID", referencedColumnName="roleID")},
* inverseJoinColumns={@JoinColumn(name="extendsRoleID", referencedColumnName="roleID")}
* )
*/
public $extends;
public function __construct() {
$this->extends = new ArrayCollection;
$this->extendedBy = new ArrayCollection;
}
}

View File

@@ -251,6 +251,23 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase
$this->assertValidDQL("SELECT (SELECT (SUM(u.id) / COUNT(u.id)) FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'");
}
/**
* @group DDC-1079
*/
public function testSelectLiteralInSubselect()
{
$this->assertValidDQL('SELECT (SELECT 1 FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u');
$this->assertValidDQL('SELECT (SELECT 0 FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u');
}
/**
* @group DDC-1077
*/
public function testConstantValueInSelect()
{
$this->assertValidDQL("SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u", true);
}
public function testDuplicateAliasInSubselectPart()
{
$this->assertInvalidDQL("SELECT (SELECT SUM(u.id) / COUNT(u.id) AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u2) foo FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'");
@@ -495,6 +512,30 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase
{
$this->assertInvalidDQL('SELECT g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g');
}
/**
* @group DDC-1053
*/
public function testGroupBy()
{
$this->assertValidDQL('SELECT g.id, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g.id');
}
/**
* @group DDC-1053
*/
public function testGroupByIdentificationVariable()
{
$this->assertValidDQL('SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g');
}
/**
* @group DDC-1053
*/
public function testGroupByUnknownIdentificationVariable()
{
$this->assertInvalidDQL('SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY m');
}
}
/** @Entity */

View File

@@ -42,7 +42,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
parent::assertEquals($sqlToBeConfirmed, $query->getSql());
$query->free();
} catch (\Exception $e) {
$this->fail($e->getMessage());
$this->fail($e->getMessage() ."\n".$e->getTraceAsString());
}
}
@@ -170,6 +170,17 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
);
}*/
/**
* @group DDC-1077
*/
public function testConstantValueInSelect()
{
$this->assertSqlGeneration(
"SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u",
"SELECT c0_.name AS name0, 'foo' AS sclr1 FROM cms_users c0_"
);
}
public function testSupportsOrderByWithAscAsDefault()
{
$this->assertSqlGeneration(
@@ -851,6 +862,28 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
'SELECT f0_.id AS id0, f0_.extension AS extension1, f0_.name AS name2 FROM "file" f0_ INNER JOIN Directory d1_ ON f0_.parentDirectory_id = d1_.id WHERE f0_.id = ?'
);
}
/**
* @group DDC-1053
*/
public function testGroupBy()
{
$this->assertSqlGeneration(
'SELECT g.id, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g.id',
'SELECT c0_.id AS id0, count(c1_.id) AS sclr1 FROM cms_groups c0_ INNER JOIN cms_users_groups c2_ ON c0_.id = c2_.group_id INNER JOIN cms_users c1_ ON c1_.id = c2_.user_id GROUP BY c0_.id'
);
}
/**
* @group DDC-1053
*/
public function testGroupByIdentificationVariable()
{
$this->assertSqlGeneration(
'SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g',
'SELECT c0_.id AS id0, c0_.name AS name1, count(c1_.id) AS sclr2 FROM cms_groups c0_ INNER JOIN cms_users_groups c2_ ON c0_.id = c2_.group_id INNER JOIN cms_users c1_ ON c1_.id = c2_.user_id GROUP BY c0_.id'
);
}
}