Closed fgamess closed 1 year ago
Up. Could you confirm if it is an issue or not? @dunglas @teohhanhui
i've the same problem, if the $id property has "ORM\GeneratedValue()" it will be only read-only, as a result it is not settable for netsted update logic.
if i remove "ORM\GeneratedValue()" so it's not auto incremented, i've to set always a id for new entries - i can not set "null" to say doctrine should generate the id
i think the main problem is, that "ORM\GeneratedValue()" doesnt't mean its "read-only", it must be writeable to set existing id for update purpose.
Hi, @dunglas @teohhanhui any thoughts about this issue? I developed a customer utility that handles the patch instead of using the default PATCH from API Platform to solve this. But I don't think I approached the problem in a good way.
i've the same problem, if the $id property has "ORM\GeneratedValue()" it will be only read-only, as a result it is not settable for netsted update logic.
if i remove "ORM\GeneratedValue()" so it's not auto incremented, i've to set always a id for new entries - i can not set "null" to say doctrine should generate the id
i think the main problem is, that "ORM\GeneratedValue()" doesnt't mean its "read-only", it must be writeable to set existing id for update purpose.
I have exactly the same issue. Need to update the reference to an object with another existing (auto-generated) id. @tecbird any chance you got this working (maybe with a workaround?)
@dunglas is this a confirmed bug? I would have thought that using auto-generated IDs e.g. ORM\GeneratedValue() is more or less a standard case. Any update on this?
Hi @dunglas @teohhanhui I found a way to get this working by creating a custom data provider targeting specific resources. One practical use case where the issue happens is, for example, when having API resources which are MongoDB documents (using Doctrine ODM) and you want to patch inner embedded MongoDB documents.
Hi @fgamess. Could you please create a gist for your custom data provider. I have the same problem.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
API Platform version(s) affected: 2.5.4
Description
Using PATCH to update an API resource with new value(s) for a nested resource, the nested resource is correctly updated. Using PATCH to update an API resource with new value(s) for a nested entity which is not an API resource, the nested entity is not updated. Instead, API Platform will create a new entity from the nested entity payload provided inside the resource and insert it in the database with a new ID.
How to reproduce
Description
I have 3 doctrine entities:
Foo has one Bar (@OneToOne, nullable=true) Foo has one Baz (@OneToOne, nullable=true)
Foo.php
Bar.php
Baz.php
Assuming I have in the database:
attempt to patch Bar inside Foo:
result:
attempt to patch Baz inside Foo:
obviously, Baz does not have an IRI
result:
As you can see a new baz record has been created in the database, the record with id=1 has not been updated.
Possible Solution
Maybe we need to explore the use of PropertyMetadata as suggested by one of the member of the core team
Additional Context