我正在尝试更新与其线程ID相关的记录数.这是一个问题,我的id_thread字段不是主键.但据我所知,cakephp仅支持更新与主要ID相关的内容.
用过的代码
$this->contact->id_thread = $id;
$this->Contact->saveField('is_read','y');
Run Code Online (Sandbox Code Playgroud)
但这对我没有用.有任何想法吗 ?
我的DB结构
id |id_thread | id_sender| is_read | status
_______________________________________________
1 | 2 | 2 | n | 1
2 | 2 | 1 | n | 1
Run Code Online (Sandbox Code Playgroud)
Far*_*ray 10
saveField仅用于处理当前加载的记录.要更新同一型号的多个记录,请使用updateAll.
用法:
Model :: updateAll(array $ fields,array $ conditions)
在一次通话中更新许多记录.要更新的记录由$ conditions数组标识,要更新的字段及其值由$ fields数组标识.
在你的情况下,它看起来像这样:
$this->Contact->updateAll(
array( 'Contact.is_read' => 'y' ), //fields to update
array( 'Contact.id_thread' => $id ) //condition
);
Run Code Online (Sandbox Code Playgroud)