Is it possible to update existing data and save new data at the same time without having to loop through the array? I would like the array with the id to update and the array without an id to create a new entry. See the example below. Thank you for your help.
[Workload] => Array
(
[0] => Array
(
[phase_count] => 1
[id] => 17
[value] => {"phases":[{"rep_range":"20-30","rep_set_count":"1"}]}
[user_id] => 1
)
[4] => Array
(
[phase_count] => 1
[value] => {"phases":[{"rep_range":"20-30","rep_set_count":"1"}]}
[user_id] => 1
)
);
and then this
$this->Workload->saveAll($this->data['Workload']);
EDIT ======================================
Here is the code that actually saves this array
if($this->data){
array_walk($this->data['Workload'], function (&$value,$index){
// This will need to be changed once users are setup
if(empty($value['user_id'])){
$value['user_id'] = 1;
}
$value['value'] = json_encode($value['value']);
});
debug($this->data);
$this->Workload->saveAll($this->data['Workload']);
In fact, I do exactly that in one of my apps. If there is no ‘id’ a table entry will be created. If the ‘id’ is specified, the record will be updated.