You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the JSON-API server receives a PATCH request, the model converter will automatically fill in the existing payload attributes into the provided model instance. As a result, we have a blank model instance where only those properties are filled, which have been provided with values in the request body.
A PATCH request is designed to modify an existing document partially, but here comes the problem: When trying to work with the converted payload model instance further, we don't know if a property with a null value should be persisted to be null or if it just wasn't set in the request body. We loose the necessarry request payload context. Therefor we require an optional model method, which will provide the information, whether a certain property is intended to be null, because it needs to be "removed", or if it's just blank because it has not been provided. So something equivalent to the php isset function.
The text was updated successfully, but these errors were encountered:
After a very productive discussion with @stixxx2k we found a possible solution here. We could create a new Dogado\JsonApi\Support\Model\PlainAttributesInterface that requires the following structure:
The resource converter must be extended to check if the resulting model is supporting that new interface. If it does, it will put in all attributes as plain multidimensional array using the setPlainAttributes method. The getPlainAttributes method must be implemented in a way to return the set key value collection, where one can then use the has method to check the request body attribute context.
For developer comfort, there should also be a Dogado\JsonApi\Support\Model\PlainAttributesTrait that already implements that logic.
When the JSON-API server receives a PATCH request, the model converter will automatically fill in the existing payload attributes into the provided model instance. As a result, we have a blank model instance where only those properties are filled, which have been provided with values in the request body.
A PATCH request is designed to modify an existing document partially, but here comes the problem: When trying to work with the converted payload model instance further, we don't know if a property with a
null
value should be persisted to benull
or if it just wasn't set in the request body. We loose the necessarry request payload context. Therefor we require an optional model method, which will provide the information, whether a certain property is intended to benull
, because it needs to be "removed", or if it's just blank because it has not been provided. So something equivalent to the phpisset
function.The text was updated successfully, but these errors were encountered: