Skip to content

Commit

Permalink
[doctrineGH-7864] Revert removeElement EXTRA_LAZY support.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Dec 6, 2019
1 parent bfc68b3 commit 041404e
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 409 deletions.
9 changes: 5 additions & 4 deletions docs/en/tutorials/extra-lazy-associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ can be called without triggering a full load of the collection:
- ``Collection#count()``
- ``Collection#get($key)`` (available with Doctrine 2.4)
- ``Collection#slice($offset, $length = null)``
- ``Collection#removeElement($element)`` for either owning side collections or inverse collections with orphanRemoval=true

For each of the above methods the following semantics apply:

Expand All @@ -38,9 +37,11 @@ easily using a combination of ``count`` and ``slice``.

.. warning::

Using ``removeElement`` will directly issue DELETE queries to the database.
This circumvents the flush operation and might run outside a transactional
boundary if you don't create one yourself.
``removeElement`` directly issued DELETE queries to the database from
version 2.4.0 to 2.7.0. This circumvents the flush operation and might run
outside a transactional boundary if you don't create one yourself. We
consider this a critical bug in the assumptio of how the ORM works and
reverted ``removeElement`` EXTRA_LAZY behavior in 2.7.1.


Enabling Extra-Lazy Associations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,6 @@ public function get(PersistentCollection $collection, $index)
return $this->persister->get($collection, $index);
}

/**
* {@inheritdoc}
*/
public function removeElement(PersistentCollection $collection, $element)
{
if ($persisterResult = $this->persister->removeElement($collection, $element)) {
$this->evictCollectionCache($collection);
$this->evictElementCache($this->sourceEntity->rootEntityName, $collection->getOwner());
$this->evictElementCache($this->targetEntity->rootEntityName, $element);
}

return $persisterResult;
}

/**
* {@inheritdoc}
*/
Expand Down
18 changes: 0 additions & 18 deletions lib/Doctrine/ORM/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,24 +367,6 @@ public function remove($key)
*/
public function removeElement($element)
{
if ( ! $this->initialized && $this->association['fetch'] === ClassMetadata::FETCH_EXTRA_LAZY) {
if ($this->collection->contains($element)) {
return $this->collection->removeElement($element);
}

if ($this->em->getUnitOfWork()->getEntityState($element) === UnitOfWork::STATE_NEW) {
return true;
}

$persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);

if ($persister->removeElement($this, $element) === true) {
// only owning side or orphan removal triggers successful
// delete so that we can keep this collection uninitialized.
return true;
}
}

$removed = parent::removeElement($element);

if ( ! $removed) {
Expand Down
10 changes: 0 additions & 10 deletions lib/Doctrine/ORM/Persisters/Collection/CollectionPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,6 @@ public function contains(PersistentCollection $collection, $element);
*/
public function containsKey(PersistentCollection $collection, $key);

/**
* Removes an element.
*
* @param \Doctrine\ORM\PersistentCollection $collection
* @param object $element
*
* @return mixed
*/
public function removeElement(PersistentCollection $collection, $element);

/**
* Gets an element by key.
*
Expand Down
16 changes: 0 additions & 16 deletions lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,6 @@ public function contains(PersistentCollection $collection, $element)
return (bool) $this->conn->fetchColumn($sql, $params, 0, $types);
}

/**
* {@inheritDoc}
*/
public function removeElement(PersistentCollection $collection, $element)
{
if ( ! $this->isValidEntityState($element)) {
return false;
}

list($quotedJoinTable, $whereClauses, $params, $types) = $this->getJoinTableRestrictions($collection, $element, false);

$sql = 'DELETE FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses);

return (bool) $this->conn->executeUpdate($sql, $params, $types);
}

/**
* {@inheritDoc}
*/
Expand Down
22 changes: 0 additions & 22 deletions lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,28 +166,6 @@ public function contains(PersistentCollection $collection, $element)
return $persister->exists($element, $criteria);
}

/**
* {@inheritdoc}
*/
public function removeElement(PersistentCollection $collection, $element)
{
$mapping = $collection->getMapping();

if ( ! $mapping['orphanRemoval']) {
// no-op: this is not the owning side, therefore no operations should be applied
return false;
}

if ( ! $this->isValidEntityState($element)) {
return false;
}

return $this
->uow
->getEntityPersister($mapping['targetEntity'])
->delete($element);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,6 @@ public function testInvokeContainsKey()
$this->assertFalse($persister->containsKey($collection, 0));
}

public function testInvokeRemoveElement()
{
$entity = new State("Foo");
$element = new State("Bar");
$persister = $this->createPersisterDefault();
$collection = $this->createCollection($entity);

$this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']);

$this->collectionPersister->expects($this->once())
->method('removeElement')
->with($this->equalTo($collection), $this->equalTo($element))
->will($this->returnValue(false));

$this->assertFalse($persister->removeElement($collection, $element));
}

public function testInvokeGet()
{
$entity = new State("Foo");
Expand Down
Loading

0 comments on commit 041404e

Please sign in to comment.