What is do you think is the best way to create a procedure where request is made and if there are any existing id in the database, update if not create a new one.
I was using something like below and it seems to work but is there are better way?
$id = $this->User->findByFacebookId($facebook);
if($id){
$this->User->set(array(
'facebook_id' => $facebook,
'longitude' => $longitude,
'latitude' => $latitude,
'firstname' => $firstname,
'surname' => $surname
));
$this->User->id = $id['User']['id'];
$this->User->save($this->data);
Yup, CakePHP basically does this by default. If your data has no
idfield anINSERTstatement is issued, whereas if there is anidfield it issuesUPDATE ... WHERE ID = ?.Just to show how simply this can be done, below is a way to do the same without even calling
Model::set()or updating theModel::idproperty: