我创建了一堆代码,用于更新另一个模型的关联模型字段。
我有3个型号:
1. Review
2. Application
3. Stat
在我的ReviewsController.php
中 foreach ($this->request->data['Review']['Mentee'] as $mentee) {
$this->loadModel('Application');
$this->Application->id = $mentee;
pr($this->Application);
$this->Application->Stat->saveField('second_video_observation_completed', $this->request->data['Review']['third_video_setting']);
}
我正在尝试更新second_video_observation_completed
模型
Stat
字段
$this->Application
$this->Application->Stat
我通过DebugKit检查了sql日志,但是它插入了新记录而不是更新Stat
Application w/ id 858
个INSERT INTO `ntc_development`.`stats` (`second_video_observation_completed`, `modified`, `created`) VALUES ('0', '2014-04-23 07:49:58', '2014-04-23 07:49:58')
记录。
{{1}}
答案 0 :(得分:0)
在saveField
模型上使用Stat
您需要为id
模型而不是Stat
模型设置Application
。
$this->Application->Stat->id = 'YOUR_ID';
$this->Application->Stat->saveField('second_video_observation_completed', $this->request->data['Review']['third_video_setting']);