1
0
mirror of synced 2025-01-17 22:11:41 +03:00

Update EntityRepository and PersistentCollection to new Criteria#expr() method instead of having to implement themselves.

This commit is contained in:
Benjamin Eberlei 2012-08-01 21:37:22 +02:00
parent 79a04b295f
commit 104a76a6b1
7 changed files with 19 additions and 55 deletions

View File

@ -42,11 +42,6 @@ use Doctrine\Common\Collections\ExpressionBuilder;
*/
class EntityRepository implements ObjectRepository, Selectable
{
/**
* @var Doctrine\Common\Collections\ExpressionBuilder
*/
private static $expressionBuilder;
/**
* @var string
*/
@ -277,17 +272,5 @@ class EntityRepository implements ObjectRepository, Selectable
return new ArrayCollection($persister->loadCriteria($criteria));
}
/**
* Return Builder object that helps with building criteria expressions.
*
* @return \Doctrine\Common\Collections\ExpressionBuilder
*/
public function expr()
{
if (self::$expressionBuilder === null) {
self::$expressionBuilder = new ExpressionBuilder();
}
return self::$expressionBuilder;
}
}

View File

@ -46,11 +46,6 @@ use Closure;
*/
final class PersistentCollection implements Collection, Selectable
{
/**
* @var Doctrine\Common\Collections\ExpressionBuilder
*/
static private $expressionBuilder;
/**
* A snapshot of the collection at the moment it was fetched from the database.
* This is used to create a diff of the collection at commit time.
@ -820,7 +815,7 @@ final class PersistentCollection implements Collection, Selectable
$targetClass = $this->em->getClassMetadata(get_class($this->owner));
$id = $targetClass->getSingleIdReflectionProperty()->getValue($this->owner);
$builder = $this->expr();
$builder = Criteria::expr();
$ownerExpression = $builder->eq($this->backRefFieldName, $id);
$expression = $criteria->getWhereExpression();
$expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;
@ -831,19 +826,5 @@ final class PersistentCollection implements Collection, Selectable
return new ArrayCollection($persister->loadCriteria($criteria));
}
/**
* Return Builder object that helps with building criteria expressions.
*
* @return \Doctrine\Common\Collections\ExpressionBuilder
*/
public function expr()
{
if (self::$expressionBuilder === null) {
self::$expressionBuilder = new ExpressionBuilder();
}
return self::$expressionBuilder;
}
}

@ -1 +1 @@
Subproject commit 15b04ec520ccded3dc0eba65b12a69ff1931360f
Subproject commit 0f7ba7fa7179bf445779f63fe5ccad355c81c06b

View File

@ -484,13 +484,13 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyEmployee");
$users = $repository->matching(new Criteria(
$repository->expr()->eq('department', 'IT')
Criteria::expr()->eq('department', 'IT')
));
$this->assertEquals(1, count($users));
$repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyManager");
$users = $repository->matching(new Criteria(
$repository->expr()->eq('department', 'IT')
Criteria::expr()->eq('department', 'IT')
));
$this->assertEquals(1, count($users));
}

View File

@ -582,7 +582,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->eq('username', 'beberlei')
Criteria::expr()->eq('username', 'beberlei')
));
$this->assertEquals(1, count($users));
@ -597,7 +597,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->neq('username', 'beberlei')
Criteria::expr()->neq('username', 'beberlei')
));
$this->assertEquals(3, count($users));
@ -612,7 +612,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->in('username', array('beberlei', 'gblanco'))
Criteria::expr()->in('username', array('beberlei', 'gblanco'))
));
$this->assertEquals(2, count($users));
@ -627,7 +627,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->notIn('username', array('beberlei', 'gblanco', 'asm89'))
Criteria::expr()->notIn('username', array('beberlei', 'gblanco', 'asm89'))
));
$this->assertEquals(1, count($users));
@ -642,7 +642,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->lt('id', $firstUserId + 1)
Criteria::expr()->lt('id', $firstUserId + 1)
));
$this->assertEquals(1, count($users));
@ -657,7 +657,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->lte('id', $firstUserId + 1)
Criteria::expr()->lte('id', $firstUserId + 1)
));
$this->assertEquals(2, count($users));
@ -672,7 +672,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->gt('id', $firstUserId)
Criteria::expr()->gt('id', $firstUserId)
));
$this->assertEquals(3, count($users));
@ -687,7 +687,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$users = $repository->matching(new Criteria(
$repository->expr()->gte('id', $firstUserId)
Criteria::expr()->gte('id', $firstUserId)
));
$this->assertEquals(4, count($users));

View File

@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
use Doctrine\Tests\Models\ECommerce\ECommerceFeature;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\Common\Collections\Criteria;
require_once __DIR__ . '/../../TestInit.php';
@ -161,14 +161,14 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId());
$features = $product->getFeatures();
$results = $features->matching(new \Doctrine\Common\Collections\Criteria(
$features->expr()->eq('description', 'Model writing tutorial')
$results = $features->matching(new Criteria(
Criteria::expr()->eq('description', 'Model writing tutorial')
));
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results);
$this->assertEquals(1, count($results));
$results = $features->matching(new \Doctrine\Common\Collections\Criteria());
$results = $features->matching(new Criteria());
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results);
$this->assertEquals(2, count($results));

View File

@ -343,13 +343,13 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract");
$contracts = $repository->matching(new Criteria(
$repository->expr()->eq('salesPerson', $this->salesPerson->getId())
Criteria::expr()->eq('salesPerson', $this->salesPerson->getId())
));
$this->assertEquals(3, count($contracts));
$repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFixContract");
$contracts = $repository->matching(new Criteria(
$repository->expr()->eq('salesPerson', $this->salesPerson->getId())
Criteria::expr()->eq('salesPerson', $this->salesPerson->getId())
));
$this->assertEquals(1, count($contracts));
}