Initialize the Input DTO For Partial Update in 2.7 and 3.0 #4916
Replies: 6 comments 4 replies
-
Exists here: https://api-platform.com/docs/main/core/dto/ |
Beta Was this translation helpful? Give feedback.
-
After some investigation, I've come up with an idea to solve this by decorating the Behavior examplesKeep existing valueRequest
Response
Update FieldRequest
Response
Unset FieldRequest
Response
It's somewhat hacky but works. I had to override the data attribute to null in the request to bypass this block that overrides the core/src/Symfony/EventListener/DeserializeListener.php Lines 71 to 79 in 205f59f |
Beta Was this translation helpful? Give feedback.
-
Any news ? |
Beta Was this translation helpful? Give feedback.
-
In addition to the above when we use custom input DTO with PUT operation in the $context which is passed to the State Processor we will have 'data' which is an instance of DTO and 'previous_data' which is a clone of the actual loaded resource. Since previous data is a cloned resource object it means that it is not managed by Doctrine's Unit Of Work. Any modification on that resource will cause INSERT operation instead of UPDATE in doctrine. So this prevent us to do the following:
Instead we need to do the following:
|
Beta Was this translation helpful? Give feedback.
-
@jelovac Thanks a lot for this hint (and the research you very likely put into this). This did also break our migration of a data transformer to a processor. (The purpose here was also to populate an actual API resource from data of a custom input with custom validation.) Too bad that data transformers are deprecated (without apparent reason) and no equal replacement in place ... |
Beta Was this translation helpful? Give feedback.
-
IMHO the way we implemented DTOs is wrong. I want to deprecate
Then in a provider / processor do whatever you want. |
Beta Was this translation helpful? Give feedback.
-
(Wasn't aware of the discussions thing. This is great!)
Currently there is an entire documentation section dedicated on how to handle partial updates with a PATCH request.
It seems this is no longer documented for the upcoming
2.7
and3.0
.It has been raised in #4613 (comment) but seeing as it isn't a bug I thought it was more appropriate to ask here.
Beta Was this translation helpful? Give feedback.
All reactions