[英]Update record where category_id=0
I set category_id to 0 and category id is auto increment. 我将category_id设置为0,类别ID是自动增量。 so I update this record in cakephp then cakephp will insert this record insted of update this record. 所以我在cakephp中更新了这条记录,然后cakephp将插入此记录更新此记录。
$this->Category->id=$id;
$this->Category->save($this->data);
Pls help me... 请帮助我...
There's an implicit assumption with CakePHP that all identifiers are truthy: CakePHP有一个隐含的假设 ,即所有标识符都是真实的:
/**
* Returns the current record's ID
*
* @param integer $list Index on which the composed ID is located
* @return mixed The ID of the current record, false if no ID
*/
public function getID($list = 0) {
if (empty($this->id) || ...) {
return false;
}
...
as such trying to save with an id of 0 will not work, causing Cake to attempt an insert even if a row exists with that falsey id. 因此尝试以id为0保存将无法工作,导致Cake尝试插入,即使存在具有该falsey id的行。
Not sure if I understand you correctly, but if you want to update ALL records WHERE category_id=0 then this code would be effecient: 不确定我是否理解正确,但如果你想更新所有记录WHERE category_id = 0那么这段代码将是有效的:
$this->Category->updateAll(
$this->data,
array('Category.category_id' => 0)
);
Cakephp will update record if id is greater then 0 other wise it insert new record. 如果id大于0,Cakephp将更新记录,否则它会插入新记录。 So try to change id 0 to greater than 0. Try this. 因此,尝试将id 0更改为大于0.试试这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.