我有一个插入查询,但它的工作方式与update
相同控制器
public function home()
{
$this->loadModel("Ratings");
$aaddRatings = $this->Ratings->addRatings($this->data['id'],$this->data['searches'],$this->data['name'],$this->data['email'],$this->data['review'],$this->data['rating']);
$this->set(compact('aaddRatings'));
}
模型
public function addRatings($id,$searches,$name,$email,$review,$rating)
{
$this->create();
$aaddRatings =$this->save(array('id'=>$id,'searches'=>$searches,'name'=>$name,'email' => $email,'review' => $review,'rating' => $rating));
return($aaddRatings);
}
调试
SELECT COUNT(*) AS `count` FROM `milgyonu_mber`.`ratings` AS `Ratings` WHERE `Ratings`.`id` = '19' 1 1 1
2 SELECT COUNT(*) AS `count` FROM `milgyonu_mber`.`ratings` AS `Ratings` WHERE `Ratings`.`id` = '19' 1 1 1
3 SELECT COUNT(*) AS `count` FROM `milgyonu_mber`.`ratings` AS `Ratings` WHERE `Ratings`.`id` = '19' 1 1 1
4 UPDATE `milgyonu_mber`.`ratings` SET `action` = 'NO', `id` = '19', `searches` = 'Advanced Neurology & Super Speciality Hospital', `name` = 'shyam', `email` = 'test@gmail.com', `review` = 'test msg', `rating` = '2' WHERE `milgyonu_mber`.`ratings`.`id` = '19'
答案 0 :(得分:4)
这是因为您设置了id字段,如果保存数组中有主键,CakePHP会将其视为该记录的更新。
删除它,它应该没问题!
更新::
public function addRatings($id,$searches,$name,$email,$review,$rating) {
$this->create();
$aaddRatings =$this->save(array('id'=>$id,'searches'=>$searches,'name'=>$name,'email' => $email,'review' => $review,'rating' => $rating));
return($aaddRatings);
}
应该是:
public function addRatings($id,$searches,$name,$email,$review,$rating) {
$this->create();
$aaddRatings =$this->save(array('searches'=>$searches,'name'=>$name,'email' => $email,'review' => $review,'rating' => $rating));
return($aaddRatings);
}
如果您将其他东西设置为此模型的主键,那么您可能没有在模型中指定它