Skip to content

Commit f0c83c6

Browse files
committed
[ObjectMapper] embed collection transformer
1 parent 6b6a678 commit f0c83c6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

object_mapper.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,28 @@ 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+
431453
Mapping Multiple Targets
432454
------------------------
433455

0 commit comments

Comments
 (0)