Enforce Criteria
This commit is contained in:
parent
9d7d731090
commit
140dc92e5f
@ -191,9 +191,9 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
||||
/**
|
||||
* {@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));
|
||||
|
||||
if ($this->region->contains($key)) {
|
||||
|
@ -1835,7 +1835,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists($entity, $extraConditions = array())
|
||||
public function exists($entity, Criteria $extraConditions = null)
|
||||
{
|
||||
$criteria = $this->class->getIdentifierValues($entity);
|
||||
|
||||
@ -1843,10 +1843,6 @@ class BasicEntityPersister implements EntityPersister
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($extraConditions)) {
|
||||
$criteria = array_merge($criteria, $extraConditions);
|
||||
}
|
||||
|
||||
$alias = $this->getSQLTableAlias($this->class->name);
|
||||
|
||||
$sql = 'SELECT 1 '
|
||||
@ -1855,7 +1851,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
|
||||
list($params) = $this->expandParameters($criteria);
|
||||
|
||||
if ($extraConditions instanceof Criteria) {
|
||||
if (null !== $extraConditions) {
|
||||
$sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions);
|
||||
list($criteriaParams, $values) = $this->expandCriteriaParameters($extraConditions);
|
||||
|
||||
|
@ -319,10 +319,10 @@ interface EntityPersister
|
||||
/**
|
||||
* Checks whether the given managed entity exists in the database.
|
||||
*
|
||||
* @param object $entity
|
||||
* @param array|Criteria $extraConditions
|
||||
* @param object $entity
|
||||
* @param Criteria|null $extraConditions
|
||||
*
|
||||
* @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;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\PersistentCollection;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
|
||||
@ -227,9 +228,9 @@ class OneToManyPersister extends AbstractCollectionPersister
|
||||
// only works with single id identifier entities. Will throw an
|
||||
// exception in Entity Persisters if that is not the case for the
|
||||
// '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
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
|
||||
/**
|
||||
* EntityPersister implementation used for mocking during tests.
|
||||
@ -88,7 +89,7 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists($entity, $extraConditions = array())
|
||||
public function exists($entity, Criteria $extraConditions = null)
|
||||
{
|
||||
$this->existsCalled = true;
|
||||
}
|
||||
|
@ -433,8 +433,8 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase
|
||||
|
||||
$this->entityPersister->expects($this->once())
|
||||
->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