Enforce Criteria
This commit is contained in:
parent
9d7d731090
commit
140dc92e5f
@ -191,9 +191,9 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function exists($entity, $extraConditions = array())
|
public function exists($entity, Criteria $extraConditions = null)
|
||||||
{
|
{
|
||||||
if (empty($extraConditions)) {
|
if (null === $extraConditions) {
|
||||||
$key = new EntityCacheKey($this->class->rootEntityName, $this->class->getIdentifierValues($entity));
|
$key = new EntityCacheKey($this->class->rootEntityName, $this->class->getIdentifierValues($entity));
|
||||||
|
|
||||||
if ($this->region->contains($key)) {
|
if ($this->region->contains($key)) {
|
||||||
|
@ -1835,7 +1835,7 @@ class BasicEntityPersister implements EntityPersister
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function exists($entity, $extraConditions = array())
|
public function exists($entity, Criteria $extraConditions = null)
|
||||||
{
|
{
|
||||||
$criteria = $this->class->getIdentifierValues($entity);
|
$criteria = $this->class->getIdentifierValues($entity);
|
||||||
|
|
||||||
@ -1843,10 +1843,6 @@ class BasicEntityPersister implements EntityPersister
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($extraConditions)) {
|
|
||||||
$criteria = array_merge($criteria, $extraConditions);
|
|
||||||
}
|
|
||||||
|
|
||||||
$alias = $this->getSQLTableAlias($this->class->name);
|
$alias = $this->getSQLTableAlias($this->class->name);
|
||||||
|
|
||||||
$sql = 'SELECT 1 '
|
$sql = 'SELECT 1 '
|
||||||
@ -1855,7 +1851,7 @@ class BasicEntityPersister implements EntityPersister
|
|||||||
|
|
||||||
list($params) = $this->expandParameters($criteria);
|
list($params) = $this->expandParameters($criteria);
|
||||||
|
|
||||||
if ($extraConditions instanceof Criteria) {
|
if (null !== $extraConditions) {
|
||||||
$sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions);
|
$sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions);
|
||||||
list($criteriaParams, $values) = $this->expandCriteriaParameters($extraConditions);
|
list($criteriaParams, $values) = $this->expandCriteriaParameters($extraConditions);
|
||||||
|
|
||||||
|
@ -319,10 +319,10 @@ interface EntityPersister
|
|||||||
/**
|
/**
|
||||||
* Checks whether the given managed entity exists in the database.
|
* Checks whether the given managed entity exists in the database.
|
||||||
*
|
*
|
||||||
* @param object $entity
|
* @param object $entity
|
||||||
* @param array|Criteria $extraConditions
|
* @param Criteria|null $extraConditions
|
||||||
*
|
*
|
||||||
* @return boolean TRUE if the entity exists in the database, FALSE otherwise.
|
* @return boolean TRUE if the entity exists in the database, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public function exists($entity, $extraConditions = array());
|
public function exists($entity, Criteria $extraConditions = null);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Persisters;
|
namespace Doctrine\ORM\Persisters;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\Criteria;
|
||||||
use Doctrine\ORM\PersistentCollection;
|
use Doctrine\ORM\PersistentCollection;
|
||||||
use Doctrine\ORM\UnitOfWork;
|
use Doctrine\ORM\UnitOfWork;
|
||||||
|
|
||||||
@ -227,9 +228,9 @@ class OneToManyPersister extends AbstractCollectionPersister
|
|||||||
// only works with single id identifier entities. Will throw an
|
// only works with single id identifier entities. Will throw an
|
||||||
// exception in Entity Persisters if that is not the case for the
|
// exception in Entity Persisters if that is not the case for the
|
||||||
// 'mappedBy' field.
|
// 'mappedBy' field.
|
||||||
$id = current($uow->getEntityIdentifier($coll->getOwner()));
|
$criteria = new Criteria(Criteria::expr()->eq($mapping['mappedBy'], $coll->getOwner()));
|
||||||
|
|
||||||
return $persister->exists($element, array($mapping['mappedBy'] => $id));
|
return $persister->exists($element, $criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Doctrine\Tests\Mocks;
|
namespace Doctrine\Tests\Mocks;
|
||||||
|
use Doctrine\Common\Collections\Criteria;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EntityPersister implementation used for mocking during tests.
|
* EntityPersister implementation used for mocking during tests.
|
||||||
@ -88,7 +89,7 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function exists($entity, $extraConditions = array())
|
public function exists($entity, Criteria $extraConditions = null)
|
||||||
{
|
{
|
||||||
$this->existsCalled = true;
|
$this->existsCalled = true;
|
||||||
}
|
}
|
||||||
|
@ -433,8 +433,8 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase
|
|||||||
|
|
||||||
$this->entityPersister->expects($this->once())
|
$this->entityPersister->expects($this->once())
|
||||||
->method('exists')
|
->method('exists')
|
||||||
->with($this->equalTo($entity), $this->equalTo(array()));
|
->with($this->equalTo($entity), $this->equalTo(null));
|
||||||
|
|
||||||
$this->assertNull($persister->exists($entity, array()));
|
$this->assertNull($persister->exists($entity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user