I need to modify the $this->request->data before it’s saved via my model’s saveAssociated method, but it’s not modifying the data to save, I can verify this because if I do it directly in the controller it works.
My model ApplicationVersionFive attempt:
<?php
App::uses('HttpSocket', 'Network/Http', 'HttpResponse');
class ApplicationVersionFive extends AppModel
{
public $name = 'ApplicationVersionFive';
public $hasMany = array('RedirectVersionFive','ApplicationPromotionVersionFive', 'ApplicationApiLinkVersionFive');
public $hasOne = array('ApplicationResponseVersionFive','ApplicationPaydayVersionFive','ApplicationInstallmentVersionFive','ApplicationSecuredVersionFive','ApplicationDebtmgmtVersionFive','ApplicationReclaimVersionFive', 'ApplicationPaydayIcicleHashVersionFive');
/*
** Perform something before a model saves
** https://book.cakephp.org/2/en/models/callback-methods.html#beforesave
*/
public function beforeSave($options = array()) {
$this->data['ApplicationVersionFive']['ApplicationVersionFive'] = $this->data['ApplicationVersionFive']['Application']
// continue with save attempt
return true;
}
}
In my controller I’ve tried both methods:
// NOT WORKING: this should pass data to `beforeSave` and then map it
$resultVersionFiveModel = $this->ApplicationVersionFive->saveAssociated($this->request->data);
// WORKING: if I manually build it up here then it saves
$test = [
'ApplicationVersionFive' => $this->request->data['Application']
];
$resultVersionFiveModel = $this->ApplicationVersionFive->saveAssociated($test);
How can I get my beforeSave to map my data so I can simply pass $this->request->data to it?