-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[ObjectMapper] embed collection transformer #60442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
36eef03 to
2da896a
Compare
src/Symfony/Component/ObjectMapper/Tests/Fixtures/TransformCollection/A.php
Show resolved
Hide resolved
|
We're already using this on a project and it works quite well. |
|
How do you use it? How is this supposed when using sources only? class UserDto {
/**
* @var OrganizationMembershipDto[]
*/
#[Map(transform: new MapCollection(), source: "memberships")]
public array $memberships;
}will throw: Like ive mentioned in #61116 theres is currently no API in object mapper to provide metadata to transformers and without this transformers are unable to guess type of target value. TDLR; Only works when mapping target is defined on source. |
39aab74 to
68b8bdd
Compare
src/Symfony/Component/ObjectMapper/Tests/Fixtures/TransformCollection/TransformCollectionC.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/ObjectMapper/Tests/Fixtures/TransformCollection/TransformCollectionD.php
Outdated
Show resolved
Hide resolved
|
Thank you @soyuka. |
|
Am I right there is currently no way to specify which target class a collection item should be mapped to, in case when there are multiple mapped classes? So even if I make my own MapCollection transformer, the callback signature |
This is not supported, this transformer only transforms to a collection of a single type. You can create your own transform and gather type at runtime but this is not optimal. Please open a new issue and detail your usage. |
|
@soyuka The problem isn't about a mixed collection type but rather multiple possible collections of a single type. Tried to explain the problem I'm having in more detail: |
This is another approach to embeded collection mapping that avoids changing the ObjectMapper. Even if this doesn't land in the component it'd be a good thing to document. Let me know your thoughts.