I'm having difficulty using Cakephp 3 patchEntity to save associated models. The models involved are summarized here
My UsersTempTable
public function initialize(array $config)
{
$this->table('users_temp');
$this->displayField('name');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->hasOne( 'UsersExtraTemp', [
'foreignKey' => 'user_id'
]);
}
Then my UsersExtraTempTable
public function initialize(array $config)
{
$this->table('users_extra_temp');
$this->displayField('id');
$this->primaryKey('id');
$this->belongsTo('UsersTemp', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
}
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['user_id'], 'UsersTemp'));
return $rules;
}
Mi function to save the data:
$user = $this->newEntity();
$user = $this->patchEntity($user, $this->request->data, [
'associated' => ['UsersTemp.UsersExtraTemp']
]);
$this->save( $user, ['associated' => ['UsersExtraTemp']] );
And my array of data print by $this->debug()
(
[name] => name
[lastname] => lastname
[email] => email@email.com
[password] => password
[passwordConfirm] => repeatPassord
[UsersExtraTemp] => Array
(
[google_token] => sjskdasdadk2
)
)
I get a row created for user_temp in the database but nothing for the one users_extra that I'm expecting. Any idea what I'm doing wrong please?