1 つのフォームで 2 つのテーブルのデータを更新したいのですが、データは 1 つのテーブルでのみ更新され、既存のレコードを更新する代わりに 2 番目のテーブルに挿入されます。これが私のコードです--
ファイルを閲覧する:
echo $this->Form->create('Question');
echo $this->Form->input('question');
foreach (range(0,2) as $index)
{
echo $this->Form->input('Option.'.$index.'.poll_options');
}
echo $this->Form->input('id',array('type'=>'hidden'));
echo $this->Form->end('Save Poll');
コントローラ ファイル:
$data=$this->Question->findById($id);
if($this->request->is('post') || $this->request->is('put'))
{
if($this->Question->saveAll($this->request->data))
{
$this->Session->setFlash('Question has been updated');
$this->redirect(array('action'=>'index'));
}
else
{
$this->Session->setFlash('Question has not been updated');
}
}
if(!$this->request->data)
{
$this->request->data=$data;
}