I'm working inside a Cake PHP 2 project and need to save data from a model called Application into an identical model (just with a different name) called ApplicationVersionFive.
Application is saved using saveAssociated which takes the request data and saves it, I'm trying to simply call a $this->ApplicationVersionFive->saveAssociated() straight after where my regular Application is saved but nothing is saving to the database.
Here's my Application model:
<?php
App::uses('HttpSocket', 'Network/Http', 'HttpResponse');
class Application extends AppModel
{
public $name = 'Application';
public $hasMany = array('Redirect','ApplicationPromotion', 'ApplicationApiLink');
public $hasOne = array('ApplicationResponse','ApplicationPayday','ApplicationInstallment','ApplicationSecured','ApplicationDebtmgmt','ApplicationReclaim', 'ApplicationPaydayIcicleHash');
/*
** Perform something after a model save
** https://book.cakephp.org/2/en/models/callback-methods.html#aftersave
*/
public function afterSave($created, $options) {
}
}
And here's my ApplicationVersionFive:
<?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');
}
Then I'm attempting to save in my controller:
// finally, save to db
// TODO: save to Version 5 model
$r = $this->Application->saveAssociated($this->request->data, array('deep' => true, 'settings' => $this->_settings));
$this->ApplicationVersionFive->saveAssociated($this->request->data, array('deep' => true, 'settings' => $this->_settings));
Unfortunately I cannot attach my whole controller, it's thousands of lines long, just a legacy business thing, what could I change to save to this separate model, effectively duplicating the data just under a different model name.