File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -428,6 +428,28 @@ And the related target object must define the ``createFromLegacy()`` method::
428
428
}
429
429
}
430
430
431
+ Mapping Collections
432
+ -------------------
433
+
434
+ By default, ObjectMapper does not map arrays or traversable collections.
435
+ To map each item in a collection (such as an array of DTOs to an array of entities), you **must ** use the `MapCollection ` transformer explicitly:
436
+
437
+ Example::
438
+
439
+ use Symfony\Component\ObjectMapper\Attribute\Map;
440
+ use Symfony\Component\ObjectMapper\Transform\MapCollection;
441
+
442
+ class ProductListInput
443
+ {
444
+ #[Map(transform: new MapCollection())]
445
+ /** @var ProductInput[] */
446
+ public array $products;
447
+ }
448
+
449
+ This configuration tells ObjectMapper to map each item in the `products ` array using the usual mapping rules.
450
+
451
+ If you do not add `transform: new MapCollection() `, the array will be mapped as-is.
452
+
431
453
Mapping Multiple Targets
432
454
------------------------
433
455
You can’t perform that action at this time.
0 commit comments