File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -428,6 +428,32 @@ And the related target object must define the ``createFromLegacy()`` method::
428428 }
429429 }
430430
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+
453+ .. versionadded :: 7.4
454+
455+ The MapCollection component was introduced in Symfony 7.4.
456+
431457Mapping Multiple Targets
432458------------------------
433459
You can’t perform that action at this time.
0 commit comments