Basically, I want to achieve the same thing as ON DUPLICATE KEY in MySQL.
Here’s a contrived example:
$rec = array('Foo' => array(
'id' => 999, // Assume there isn't already a record with this id
'website' => 'google'
));
$this->Foo->save($rec);
// save with different 'website' value
$rec['Foo']['website'] = 'stackoverflow';
$this->Foo->save($rec);
Does the last line update the record that was created just a few lines up?
If you call
save(), supplying a record with an existingid(or whatever is the primary key), it will update, otherwise it will create a new record.So in your case, yes, it would update the record that was first created at the top.
Update
Here’s the supporting documentation:
Under the documentation for
Model::save().