File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -424,6 +424,33 @@ And the related target object must define the ``createFromLegacy()`` method::
424424 }
425425 }
426426
427+ Mapping Collections
428+ -------------------
429+
430+ By default, ObjectMapper does not map arrays or traversable collections. To map
431+ each item in a collection (for example, mapping an array of DTOs to an array of
432+ entities), you **must ** explicitly use the ``MapCollection `` transformer:
433+
434+ Example::
435+
436+ use Symfony\Component\ObjectMapper\Attribute\Map;
437+ use Symfony\Component\ObjectMapper\Transform\MapCollection;
438+
439+ class ProductListInput
440+ {
441+ #[Map(transform: new MapCollection())]
442+ /** @var ProductInput[] */
443+ public array $products;
444+ }
445+
446+ With this configuration, ObjectMapper maps each item in the ``products `` array
447+ according to the usual mapping rules. Without ``transform: new MapCollection() ``,
448+ the array is left unchanged.
449+
450+ .. versionadded :: 7.4
451+
452+ The ``MapCollection `` transformer was introduced in Symfony 7.4.
453+
427454Mapping Multiple Targets
428455------------------------
429456
You can’t perform that action at this time.
0 commit comments