Skip to content

docs(dto): relations between mapped resources - #2345

Open
audain-dg wants to merge 1 commit into
api-platform:mainfrom
audain-dg:feat/mapped-relations
Open

audain-dg wants to merge 1 commit into
api-platform:mainfrom
audain-dg:feat/mapped-relations

Conversation

@audain-dg

@audain-dg audain-dg commented Sep 20, 2026

Copy link
Copy Markdown

Documents relations between mapped DTO resources, which core/dto.md does not cover today: every example there maps scalars only.

A relation typed on another DTO Resource is the case where the object mapper needs help. It builds objects and has no identity map, so the related DTO reaches the entity's property as-is and PropertyAccess fails:

Expected argument of type "?App\Entity\Author", "App\Api\Resource\Author" given at property path "author"

Declaring the reverse mapping does not fix it either — it moves the failure to the flush, with A new entity was found through the relationship, and cascading inserts a duplicate row instead.

The new section sits at the end of "1. The DTO Resource (State Options)", right before the Input/Output DTO chapter, and covers:

  • the error, and why the reverse mapping is not the answer;
  • ManagedEntityTransform on a to-one and on a to-many;
  • why nothing is declared per relation (the managed class comes from the related resource's stateOptions, the identifier from its metadata — never assumed to be id);
  • why only the write direction needs it.

Documents the feature added in api-platform/core#8547 — to be merged once that one is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant