Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 638 Bytes

EmbedManyFieldDenormalizer.md

File metadata and controls

32 lines (26 loc) · 638 Bytes

EmbedManyFieldDenormalizer

<?php

use Chubbyphp\Deserialization\Accessor\PropertyAccessor;
use Chubbyphp\Deserialization\Denormalizer\Relation\EmbedManyFieldDenormalizer;
use MyProject\Model\ParentModel;
use MyProject\Model\ChildModel;

$parentModel = new ParentModel;
$context = ...;
$denormalizer = ...;

$fieldDenormalizer = new EmbedManyFieldDenormalizer(
    ChildModel::class,
    new PropertyAccessor('children')
);

$fieldDenormalizer->denormalizeField(
    'children',
    $parentModel,
    [['name' => 'php']],
    $context,
    $denormalizer
);

echo $parentModel
    ->getChildren()[0]
    ->getName();
// 'php'