-
Notifications
You must be signed in to change notification settings - Fork 45
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
Remove simple relationship #113
Comments
Based on what I see in the tests, you may just be missing a persist() call on the entity to add it to the working set. |
The code you showed me works: $jim = $em->getRepository('AppBundle\Entity\Person')->findOneByName('Jim');
$firstFriend = $jim->getFriends()->first(); // Returns John
$jim->removeFriend($firstFriend);
$em->persist($jim);
$em->flush(); However the folowing code does not work; $jim = $em->getRepository('AppBundle\Entity\Person')->findOneByName('Jim');
$john = $em->getRepository('AppBundle\Entity\Person')->findOneByName('John');
$jim->removeFriend($john);
$em->persist($jim);
$em->flush(); In the second case, John is removed from the Friend's Array Collection in-memory but it is not persisted in the Database. |
Seems like a good test case. Feel free to submit a PR with a fix. |
I have done some tests and from the results I concluded that the getFriends() or getActors() method call before $em->persist()
$em->flush() triggers the update in the database. I have tried calling other methods and also renaming the getFriends() to getFriendss() and in those casses, the entity is not persisted. I am not sure what might cause this and I would really appreciate if someone could have a look into this. |
It's quite likely that the relationship needs to be hydrated first for the change to be detected. Fixing this would require re-writing most of the proxy generation to use a collection type that keeps track of those changes instead of just comparing them at the end. If you are up to the task, I would gladly assist and review the changes. However, I no longer actively maintain this component. |
I can't figure out how to remove a simple relationship. Suppose I have a Person Entity which has a collection of friends (also Person). Say John is friend with Jimmy. I did the following:
and the removeFriend function in Person class looks like this:
The in-memory collection is updated. John is not friend with Jimmy anymore. However, this is not persisted into the db.
The text was updated successfully, but these errors were encountered: