Update EntityRepository and PersistentCollection to new Criteria#expr() method instead of having to implement themselves.
This commit is contained in:
parent
79a04b295f
commit
104a76a6b1
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
2
lib/vendor/doctrine-common
vendored
2
lib/vendor/doctrine-common
vendored
@ -1 +1 @@
|
||||
Subproject commit 15b04ec520ccded3dc0eba65b12a69ff1931360f
|
||||
Subproject commit 0f7ba7fa7179bf445779f63fe5ccad355c81c06b
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user