Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I would like to use the new ObjectMapper (https://symfony.com/doc/current/object_mapper.html) to map an Entity that has an array of another entity as its members to a Dto. // Entity#[ORM\Entity]class ExerciseResult{/** * @var Collection<int, CoordinationComponentResult> */ #[ORM\OneToMany(mappedBy:'exerciseResult', targetEntity: CoordinationComponentResult::class)]privateCollection$koordinationComponentResults;}// Dtos#[Map(source: ExerciseResult::class)]class ExerciseResultDto{/** @var CoordinationComponentResultDto[] */ #[Map(source:'coordinationComponentResults.toArray')]publicarray$coordinationComponentResults;// ...}#[Map(source: CoordinationComponentResult::class)]class CoordinationComponentResultDto{publicint$id;publicint$reachedScore;publicfloat$accuracy;} When mapping the Entity to its Dto $mapper =newObjectMapper(propertyAccessor: PropertyAccess::createPropertyAccessor());$exerciseResultDto =newExerciseResultDto();$mapper->map($exerciseResult,$exerciseResultDto); the resulting #[Map(source:'coordinationComponentResults.toArray', target: CoordinationComponentResultDto::class .'[]' )]public array$coordinationComponentResults; But this does not work either. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 0 comments
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment