I am learning cakePHP 3.0 and have some problem with saving associated data on my model.
I try to save a Client with associated data of ClientPreferences
ClientTable
class ClientsTable extends Table
{
public function initialize(array $config)
{
(...)
$this->belongsTo('ClientPreferences', [
'foreignKey' => 'client_preferences_id'
]);
}
}
ClientController
$aClient = $this->Clients->newEntity();
$aClient = $this->Clients->patchEntity($aClient, $this->request->data);
$aClientPreference = $this->Clients->ClientPreferences->newEntity();
$aClientPreference->my_field = 'my value';
$aClient->ClientPreferences = $aClientPreference;
$this->Clients->save($aClient, ['associated' => ['ClientPreferences']];
The Client entity is correctly saved, but not the associated ClientPreferences entity and there is no error thrown by Cake.
I have tried to follow this : http://book.cakephp.org/3.0/en/orm/saving-data.html#saving-with-associations
But haven't find any issue to do it properly. Do anybody have an advice ?
Thank you in advance.