I'm working in a legacy Cake PHP 2 project and have a model with some defined relationships. My request data I need to map as it's got other model names in it, so I'm doing this in my new model's beforeSave method.
When I try to save, it's saving the upper-most ApplicationVersionFive model just fine, but the related models such as ApplicationPaydayVersionFive just aren't saving and I have no idea why, it should be saving because my tables are configured:
My tables have a prefix in the database.php file.
- model:
ApplicationVersionFive, table:tlp_application_version_fives - model:
ApplicationPaydayVersionFive, table:tlp_application_payday_version_fives
ApplicationVersionFive model
<?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()) {
$application = $this->data;
$this->data = [
'ApplicationVersionFive' => $application['ApplicationVersionFive']['Application'],
'ApplicationPaydayVersionFive' => $application['ApplicationVersionFive']['ApplicationPayday'],
'ApplicationResponseVersionFive' => $application['ApplicationVersionFive']['ApplicationResponse'],
'ApplicationPaydayIcicleHashVersionFive' -> $application['ApplicationVersionFive']['ApplicationPaydayIcicleHash']
];
// continue with save attempt
return true;
}
}
ApplicationPaydayVersionFive model
<?php
class ApplicationPaydayVersionFive extends AppModel
{
public $name = 'ApplicationPaydayVersionFive';
public $belongsTo = 'ApplicationVersionFive';
}
Called via:
$this->ApplicationVersionFive->saveAssociated($this->request->data, array('deep' => true));
What am I missing to get my linked models to save?
I should also be seeing the Application's model ID saved into the application_version_five_id column on my Payday model but I'm not:

