Merge branch 'DDC-573'
This commit is contained in:
commit
8b766b6c92
@ -888,6 +888,40 @@ class QueryBuilder
|
|||||||
. (isset($options['post']) ? $options['post'] : '');
|
. (isset($options['post']) ? $options['post'] : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset DQL parts
|
||||||
|
*
|
||||||
|
* @param array $parts
|
||||||
|
* @return QueryBuilder
|
||||||
|
*/
|
||||||
|
public function resetDQLParts($parts = null)
|
||||||
|
{
|
||||||
|
if (is_null($parts)) {
|
||||||
|
$parts = array_keys($this->_dqlParts);
|
||||||
|
}
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
$this->resetDQLPart($part);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset single DQL part
|
||||||
|
*
|
||||||
|
* @param string $part
|
||||||
|
* @return QueryBuilder;
|
||||||
|
*/
|
||||||
|
public function resetDQLPart($part)
|
||||||
|
{
|
||||||
|
if (is_array($this->_dqlParts[$part])) {
|
||||||
|
$this->_dqlParts[$part] = array();
|
||||||
|
} else {
|
||||||
|
$this->_dqlParts[$part] = null;
|
||||||
|
}
|
||||||
|
$this->_state = self::STATE_DIRTY;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a string representation of this QueryBuilder which corresponds to
|
* Gets a string representation of this QueryBuilder which corresponds to
|
||||||
* the final DQL query being constructed.
|
* the final DQL query being constructed.
|
||||||
|
@ -525,4 +525,48 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
$this->assertValidQueryBuilder($qb, 'SELECT COUNT(e.id)');
|
$this->assertValidQueryBuilder($qb, 'SELECT COUNT(e.id)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResetDQLPart()
|
||||||
|
{
|
||||||
|
$qb = $this->_em->createQueryBuilder()
|
||||||
|
->select('u')
|
||||||
|
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||||
|
->where('u.username = ?1')->orderBy('u.username');
|
||||||
|
|
||||||
|
$this->assertEquals('u.username = ?1', (string)$qb->getDQLPart('where'));
|
||||||
|
$this->assertEquals(1, count($qb->getDQLPart('orderBy')));
|
||||||
|
|
||||||
|
$qb->resetDqlPart('where')->resetDqlPart('orderBy');
|
||||||
|
|
||||||
|
$this->assertNull($qb->getDQLPart('where'));
|
||||||
|
$this->assertEquals(0, count($qb->getDQLPart('orderBy')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testResetDQLParts()
|
||||||
|
{
|
||||||
|
$qb = $this->_em->createQueryBuilder()
|
||||||
|
->select('u')
|
||||||
|
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||||
|
->where('u.username = ?1')->orderBy('u.username');
|
||||||
|
|
||||||
|
$qb->resetDQLParts(array('where', 'orderBy'));
|
||||||
|
|
||||||
|
$this->assertEquals(1, count($qb->getDQLPart('select')));
|
||||||
|
$this->assertNull($qb->getDQLPart('where'));
|
||||||
|
$this->assertEquals(0, count($qb->getDQLPart('orderBy')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testResetAllDQLParts()
|
||||||
|
{
|
||||||
|
$qb = $this->_em->createQueryBuilder()
|
||||||
|
->select('u')
|
||||||
|
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||||
|
->where('u.username = ?1')->orderBy('u.username');
|
||||||
|
|
||||||
|
$qb->resetDQLParts();
|
||||||
|
|
||||||
|
$this->assertEquals(0, count($qb->getDQLPart('select')));
|
||||||
|
$this->assertNull($qb->getDQLPart('where'));
|
||||||
|
$this->assertEquals(0, count($qb->getDQLPart('orderBy')));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user