Cakephp: Update records without refering the primary key
cakephp, php
Solution
saveField is only intended to work on the currently loaded record. To update multiple records of the same model, use `updateAll`.
Usage:
Model::updateAll(array $fields, array $conditions)
Updates many records in a single call. Records to be updated are identified by the $conditions array, and fields to be updated, along with their values, are identified by the $fields array.
source
In your case, it would look like this:
$this->Contact->updateAll(
array( 'Contact.is_read' => 'y' ), //fields to update
array( 'Contact.id_thread' => $id ) //condition
);
Problem
I am trying to update number of records with respect to their thread Id. Here is a problem my id_thread field is not a primary key . But as far as I know cakephp only supporting updating content relating with primary id . Used code ``` $this->contact->id_thread = $id; $this->Contact->saveField('is_read','y'); ``` But this is not worked for me. Any ideas ? My DB structure ``` id |id_thread | id_sender| is_read | status _______________________________________________ 1 | 2 | 2 | n | 1 2 | 2 | 1 | n | 1 ```