必须有一个简单的答案但我不能在一个字段中添加一个包含多个记录的数组。我可以用一个记录来做,但是多个记录是不同的。下面的代码不允许我保存记录。我可以使用另一个保存命令并添加记录,但没有额外的字段。
为了让事情更清楚,我可以一次保存多条记录。我可以手动为这些记录添加字段,因为我需要添加用户无法添加的其他字段。
问题是我也不想保存相关模型而只需要1个模型,所以saveAssociated不是我想要的。我不想保存供应商
http://book.cakephp.org/2.0/en/models/saving-your-data.html
cant save data from 1 table to another table
if ($this->request->is('post')) {
$this->Availtmp->create();
$Availtmp = array('Availtmp' => $this->request->data['AvailabilityForTutor']);
$Availtmp['Availtmp'][0]['tutor_id'] = 2; //these fields I want to add in
// $Availtmp[1]['Availtmp']['tutor_id'] = 2;
debug($Availtmp[0]['tutor_id']) ; //this works but it wont save in saveAll
if ($this->Availtmp->saveAll($Availtmp)) {..
//if ($this->Availtmp->saveAll($this->request->data['AvailabilityForTutor']) ){//this works
data
array(
'Availtmp' => array(
(int) 0 => array(
'weekday' => 'Monday',
'start_time' => array(
'hour' => '09',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '11',
'min' => '00',
'meridian' => 'pm'
),
'id' => '99'
),
(int) 1 => array(
'weekday' => 'Tuesday',
'start_time' => array(
'hour' => '09',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '10',
'min' => '00',
'meridian' => 'pm'
),
'id' => '100'
),
(int) 2 => array(
'weekday' => 'Wednesday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '101'
),
(int) 3 => array(
'weekday' => 'Thursday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '102'
),
(int) 4 => array(
'weekday' => 'Friday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '103'
),
(int) 5 => array(
'weekday' => 'Saturday',
'start_time' => array(
'hour' => '09',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '11',
'min' => '00',
'meridian' => 'pm'
),
'id' => '104'
),
(int) 6 => array(
'weekday' => 'Sunday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '105'
)
),
(int) 0 => array(
'Availtmp' => array(
'tutor_id' => (int) 2
)
),
(int) 1 => array(
'Availtmp' => array(
'tutor_id' => (int) 2
)
),
(int) 2 => array(
'Availtmp' => array(
'tutor_id' => (int) 2
)
)
)
答案 0 :(得分:0)
我做了一些研究,看起来你不能在多记录数组中添加额外的字段,并将整个事物保存在另一个表中。 如果你有一个记录数组,并且你想将它复制到另一个表(模型),并且要复制的表有额外的字段,那么你就没有运气了。