Skip to content

Commit 041404e

Browse files
committed
[GH-7864] Revert removeElement EXTRA_LAZY support.
1 parent bfc68b3 commit 041404e

File tree

8 files changed

+5
-409
lines changed

8 files changed

+5
-409
lines changed

docs/en/tutorials/extra-lazy-associations.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ can be called without triggering a full load of the collection:
1919
- ``Collection#count()``
2020
- ``Collection#get($key)`` (available with Doctrine 2.4)
2121
- ``Collection#slice($offset, $length = null)``
22-
- ``Collection#removeElement($element)`` for either owning side collections or inverse collections with orphanRemoval=true
2322

2423
For each of the above methods the following semantics apply:
2524

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

3938
.. warning::
4039

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

4546

4647
Enabling Extra-Lazy Associations

lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,6 @@ public function get(PersistentCollection $collection, $index)
243243
return $this->persister->get($collection, $index);
244244
}
245245

246-
/**
247-
* {@inheritdoc}
248-
*/
249-
public function removeElement(PersistentCollection $collection, $element)
250-
{
251-
if ($persisterResult = $this->persister->removeElement($collection, $element)) {
252-
$this->evictCollectionCache($collection);
253-
$this->evictElementCache($this->sourceEntity->rootEntityName, $collection->getOwner());
254-
$this->evictElementCache($this->targetEntity->rootEntityName, $element);
255-
}
256-
257-
return $persisterResult;
258-
}
259-
260246
/**
261247
* {@inheritdoc}
262248
*/

lib/Doctrine/ORM/PersistentCollection.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -367,24 +367,6 @@ public function remove($key)
367367
*/
368368
public function removeElement($element)
369369
{
370-
if ( ! $this->initialized && $this->association['fetch'] === ClassMetadata::FETCH_EXTRA_LAZY) {
371-
if ($this->collection->contains($element)) {
372-
return $this->collection->removeElement($element);
373-
}
374-
375-
if ($this->em->getUnitOfWork()->getEntityState($element) === UnitOfWork::STATE_NEW) {
376-
return true;
377-
}
378-
379-
$persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);
380-
381-
if ($persister->removeElement($this, $element) === true) {
382-
// only owning side or orphan removal triggers successful
383-
// delete so that we can keep this collection uninitialized.
384-
return true;
385-
}
386-
}
387-
388370
$removed = parent::removeElement($element);
389371

390372
if ( ! $removed) {

lib/Doctrine/ORM/Persisters/Collection/CollectionPersister.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ public function contains(PersistentCollection $collection, $element);
9090
*/
9191
public function containsKey(PersistentCollection $collection, $key);
9292

93-
/**
94-
* Removes an element.
95-
*
96-
* @param \Doctrine\ORM\PersistentCollection $collection
97-
* @param object $element
98-
*
99-
* @return mixed
100-
*/
101-
public function removeElement(PersistentCollection $collection, $element);
102-
10393
/**
10494
* Gets an element by key.
10595
*

lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,6 @@ public function contains(PersistentCollection $collection, $element)
211211
return (bool) $this->conn->fetchColumn($sql, $params, 0, $types);
212212
}
213213

214-
/**
215-
* {@inheritDoc}
216-
*/
217-
public function removeElement(PersistentCollection $collection, $element)
218-
{
219-
if ( ! $this->isValidEntityState($element)) {
220-
return false;
221-
}
222-
223-
list($quotedJoinTable, $whereClauses, $params, $types) = $this->getJoinTableRestrictions($collection, $element, false);
224-
225-
$sql = 'DELETE FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses);
226-
227-
return (bool) $this->conn->executeUpdate($sql, $params, $types);
228-
}
229-
230214
/**
231215
* {@inheritDoc}
232216
*/

lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,28 +166,6 @@ public function contains(PersistentCollection $collection, $element)
166166
return $persister->exists($element, $criteria);
167167
}
168168

169-
/**
170-
* {@inheritdoc}
171-
*/
172-
public function removeElement(PersistentCollection $collection, $element)
173-
{
174-
$mapping = $collection->getMapping();
175-
176-
if ( ! $mapping['orphanRemoval']) {
177-
// no-op: this is not the owning side, therefore no operations should be applied
178-
return false;
179-
}
180-
181-
if ( ! $this->isValidEntityState($element)) {
182-
return false;
183-
}
184-
185-
return $this
186-
->uow
187-
->getEntityPersister($mapping['targetEntity'])
188-
->delete($element);
189-
}
190-
191169
/**
192170
* {@inheritdoc}
193171
*/

tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,23 +227,6 @@ public function testInvokeContainsKey()
227227
$this->assertFalse($persister->containsKey($collection, 0));
228228
}
229229

230-
public function testInvokeRemoveElement()
231-
{
232-
$entity = new State("Foo");
233-
$element = new State("Bar");
234-
$persister = $this->createPersisterDefault();
235-
$collection = $this->createCollection($entity);
236-
237-
$this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']);
238-
239-
$this->collectionPersister->expects($this->once())
240-
->method('removeElement')
241-
->with($this->equalTo($collection), $this->equalTo($element))
242-
->will($this->returnValue(false));
243-
244-
$this->assertFalse($persister->removeElement($collection, $element));
245-
}
246-
247230
public function testInvokeGet()
248231
{
249232
$entity = new State("Foo");

0 commit comments

Comments
 (0)