-
-
Notifications
You must be signed in to change notification settings - Fork 838
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
Denormalizing bidirectional ManyToOne relations don't remove items #153
Comments
Did you try to set If it doesn't work using a custom Data Provider should do the trick. |
When I do a manual test, the relation gets removed properly: $manufacturer = $this->getDoctrine()->getManager()->find("PartKeepr\\ManufacturerBundle\\Entity\\Manufacturer", 2);
$manufacturer->getIcLogos()->removeElement($manufacturer->getIcLogos()->first()); So I don't think it's a doctrine bug. For testing, I tried removing the association directly in When I simply overwrite the association with a simple array, no changes are committed into the database and that's exactly what the deserializer does:
Noteworthy: Once a relation has been established, the collection is not an |
The problem is related to Doctrine internals. I've opened a PR on PartKeepr with a workaround: partkeepr/PartKeepr#409. Let me know if you think it's OK to close this bug. |
Yes, that workaround works, but I'm not really sure why. Thank you! I think we should document the adders/removers somehow, what do you think? |
We definitely should! It works because when |
I'd like to keep this issue open as I might want to document the issue and/or provide a possible fix. As I go along migrating all entities, there might be more stuff that relies on the setter in some way. Also, the blog-api demo should be updated to reflect that behavior. |
Is the blog-api demo impacted? |
No, but a ManyToOne/OneToMany example in the blog-api would be very nice to have as a sample implementation, especially with the current setter/adder/deleter issue. Things I often miss with Symfony2 bundles in general that "full-featured" demos are rare which could be used as reference. |
Should be fixed now (not tested). Feel free to reopen is it's not the case. |
I have configured a bidirectional ManyToOne/OneToMany relation:
Owning side:
https://github.com/partkeepr/PartKeepr/blob/sf2migration/src/PartKeepr/ManufacturerBundle/Entity/Manufacturer.php#L82
Inversing side: https://github.com/partkeepr/PartKeepr/blob/sf2migration/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php#L14
When I attempt to remove items, I get the proper response from DunglasApiBundle where the removed items don't exist anymore, however, the items still persist in the database. Most likely DunglasApiBundle doesn't call
EntityMananger->remove
for removed entities, although I'm not sure if Doctrine can be configured to take care of that automatically.Note that this only seems to happen for bidirectional ManyToOne/OneToMany relations.
Here's the example request:
Response:
So the returned JSON is fine, but removals aren't stored in the database. Here's a GET on the same resource without any changes:
The text was updated successfully, but these errors were encountered: