Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] Extra lazy docs do not mention removeElement eagerness #7765

Closed
malarzm opened this issue Jul 1, 2019 · 4 comments
Closed

Comments

@malarzm
Copy link
Member

malarzm commented Jul 1, 2019

TIL that not initialized collection in EXTRA_LAZY mode will remove element with ->removeElement() from the database without waiting for a flush. I think it should be mentioned in the docs

if (! $this->initialized &&
$this->association !== null &&
$this->association->getFetchMode() === FetchMode::EXTRA_LAZY) {
if ($this->collection->contains($element)) {
return $this->collection->removeElement($element);
}
$persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);
return $persister->removeElement($this, $element);
}

@DonCallisto
Copy link

As $persister here

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

could be of two types ManyToManyPersister and OneToMany persister this is the relevant code

public function removeElement(PersistentCollection $collection, $element)

public function removeElement(PersistentCollection $collection, $element)

I think the docs should point out this situation - where applicable - both in https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/working-with-associations.html#orphan-removal and https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/extra-lazy-associations.html#extra-lazy-associations

BTW the fact that ManyToManyPersister does not contemplate orphanRemoval makes me wonder if this is a bug or is done by design.

As said in #7852 that's now closed, I'm willing to work on this PR if think is worthy.

@flaushi
Copy link
Contributor

flaushi commented Oct 4, 2019

If I see this correctly, one viable workaround is - and could well be mentioned in the docs - that if one needs the event listener to be called, one can replace

$entity->manyToManyCollection->removeElement($other);

with

$index = $entity->manyToManyCollection->indexOf($other);
if($index !== false)
    $entity->manyToManyCollection->remove($index);

... which will load the collection, but nevertheless I can imagine many people relying on the event listeners being called, so this is the only way to go....

@DonCallisto
Copy link

The intent of EXTRA_LAZY is to prevent the whole collection to be loaded so I don't think it has too much sense in this context.
Moreover how can one change that section of code?
Lastly, this is the intended behaviour.

@malarzm
Copy link
Member Author

malarzm commented Jun 28, 2020

Closing as behaviour was changed in #7940

@malarzm malarzm closed this as completed Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants