Skip to content

Commit 65b9f1e

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: Minor tweaks [ObjectMapper] embed collection transformer
2 parents 59aa97e + 20bd5cb commit 65b9f1e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

object_mapper.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
427454
Mapping Multiple Targets
428455
------------------------
429456

0 commit comments

Comments
 (0)