Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unable to update an embedded collection relation with a PATCH operation #5559

@jonag

Description

@jonag

API Platform version(s) affected: 3.1.8

Description

I'm trying to update an embedded relation with a PATCH operation. Basically this use case but with a PATCH instead of a PUT. However my relation is deleted and recreated instead of updated.

How to reproduce

  1. Create a resource with a collection.
  2. Try to update an item of this collection with a PATCH operation.

Possible Solution

I tried to debug the issue. I think the issue happens because when the request reach this line, $data['@id'] contains the id of my relation but $context[self::OBJECT_TO_POPULATE] is set and contains the entire collection instead of just the item.

If I update this line with

$childContext = $this->createChildContext($context, $attribute, $format);
$childContext[self::OBJECT_TO_POPULATE] = null;
$values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $childContext);

then the request behave as expected, but I'm really not sure that this is the right fix.

Please tell me if I can do anything to help fix the issue (or if I'm doing anything wrong).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions