docs(serialization): document element-type requirement for readableLink on collection getters#2289
Closed
soyuka wants to merge 3 commits into
Closed
Conversation
…nk on collection getters When readableLink: false is applied to a getter returning array, PropertyInfo resolves array<mixed> and cannot determine the element class, causing the relation to be embedded. Document the three remedies (PHPDoc @return, ApiProperty nativeType, typed Doctrine collection) and link to #8179.
Member
Author
|
Closing — overkill for what is ultimately a typing requirement. The closed-issue thread on api-platform/core#8179 carries the explanation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When
readableLink: falseis applied to a getter returning a barearray, Symfony PropertyInfo resolves the type asarray<mixed>. Without a known element class, API Platform cannot identify the items as API resources and falls back to embedding them — the opposite of the intended behavior. This is a configuration issue, not a framework bug (see api-platform/core#8179).What this PR adds
A new "Collection Getters and readableLink" subsection under the "Force IRI with relations of the same type" section in
core/serialization.md, documenting three remedies:@return Car[]— zero-dependency, works with all API Platform versionsApiProperty(nativeType: Type::list(Type::object(Car::class)))— explicit type viasymfony/type-info(API Platform >= 4.2)Collection<int, Car>) — return a typedCollectioninstead of a plainarrayRelated
fix/readable-link-array-collection-8179-v3will be opened againstapi-platform/coreseparately.