Save associations not working in cakephp 4


I have these nested associations :

CustomRubriques hasOne ExtendedRubriques hasMany Photos

Photos has fields id and legend

I’m trying to save legend from CustomRubriques like this :

// CustomRubriques/edit.php
echo $this->Form->control('');
echo $this->Form->control('');
echo $this->Form->control('');
echo $this->Form->control('');
// etc..
// CustomRubriquesController.php
public function edit($id)
    $rubrique = $this->CustomRubriques->findById($id)->firstOrFail();

    if ($this->request->is(['post', 'put'])) {
        $rubrique = $this->CustomRubriques->patchEntity($rubrique, $this->request->getData());

        debug($rubrique); // $rubrique->extended_rubrique->photos[0]['id'] and $rubrique->extended_rubrique->photos[0]['legend'] are well defined

        if ($this->CustomRubriques->save($rubrique, ['associated' => ['ExtendedRubriques', 'ExtendedRubriques.Photos']])) {
            return $this->redirect(['action' => 'view', $rubrique->id]);


The legend of the photos are not saved (without any error returned) and I really don’t know why !

(Note that legend is true in Photo Entity’s $_accessible )

Could anybody tell me what I’m doing wrong ?

Source: CakePHP