Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to denormalize into an ArrayCollection#61059

Unanswered
alessandro-podo asked this question inQ&A
Discussion options

In the following configuration, I would expect the RelationCollection to contain elements, but it remains empty.
If I specify array instead of RelationCollection as type in the CI Object, I get an array with Relation as elements.

Can the Serializer use Collection and if so, how does this work? Have I overlooked something in the documentation?

$data = ['id' =>1,'relations' => [                ['id' =>100,                ],            ],        ];$ci =$this->serializer->denormalize($data, Ci::class);
useDoctrine\Common\Collections\ArrayCollection;useDoctrine\Common\Collections\Collection;/** * @template-extends Collection<int, Relation> */class RelationCollectionextends ArrayCollection{}
finalreadonlyclass Ci{publicfunction__construct(publicint$id,/**         * @var RelationCollection<Relation>         */public ?RelationCollection$relations =null,    ) {}}
finalreadonlyclass Relation {publicfunction__construct(publicint$id,    )    {    }}
You must be logged in to vote

Replies: 1 comment

Comment options

ArrayCollection is constructed through an$elements argument so I guess your$data should be

['id' =>1,'relations' => ['elements' => [            ['id' =>100],        ],    ],]

Note thatRelationCollection is not generic soCi::$relations doesn’t need the PHPDoc.
(Also@template-extends an interface seems weird.)

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@alessandro-podo@MatTheCat

[8]ページ先頭

©2009-2025 Movatter.jp