mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-729: When merging many to many entities back into the repository all associations are deleted on the next flush #898
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jul 31, 2010).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user ccapndave:
When merging a DETACHED entity into the repository with a ManyToMany association, the entries in the join table are deleted on the next flush.
Many Movies have many Artists:
Assume that the database contains:
Movie: id=1, title="Movie 1"
Artist: id=1, name="Artist 1"
and that there is a entry (1, 1) in movie_artist so that there is a many-many relationship between Movie 1 and Artist 1.
I then run the following code to merge the existing associations into the entity manager:
At this point $m1 should contains merged entities reflecting the same as what is in the database.
If I now run:
the association is deleted from movie_artist and the SQL log shows DELETE FROM Movie_Artist WHERE Movie_id = '1' as having been run.
Debugging $m1 both before and after the flush shows the expected values, and $em->getUnitOfWork()->computeChangeSets() is empty before the flush.