Skip to content

Embedded relation without dedicated route #199

Description

@esistgut

I have a Product entity having a OneToMany relation with a ProductTranslation entity without the "@ApiResource" annotation. I set up the relevant serialization groups for both the normalization_context and the denormalization_context so a GET to /products/ returns as expected:

{
 	"id": 2,
 	"code": "sku123",
 	"translations": [{
 		"id": 12,
 		"name": "Pen",
 		"description": "it is a pen",
 		"locale": "en"
 	}, {
 		"id": 14,
 		"name": "Stylo",
 		"description": "il est un stylo",
 		"locale": "fr"
 	}]
 }

It is working as expected when creating a new object via POST too. My problem is when I try to update a translation via PUT to /products/2:

{
	"code": "sku123",
	"translations": [{
		"id": 12,
		"name": "Biro",
		"description": "it is still a pen",
		"locale": "en"
	}]
}

this would not update the existing relation but just add a new one (another ProductTranslation with another ID).
It works as expected if I add the "@ApiResource" annotation to the ProductTranslation entity (and change the translation id to something like "/product_translations/12") but that would also create an end point for this entity and that is wrong because it is never required to be used directly.

So my question is: is there a way to make the PUT update work for an embedded relation which does not have its own routing / end point?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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