It's not really an INSERT IGNORE
solution, but to handle this situation at the app level you'd use validation rules. If you simply attach the isUnique
validation rule to the guid
field in your model, Cake will automatically bail out of the save operation if the guid already exists.
Behind the scenes it'll make two queries to the database instead of the one that INSERT IGNORE
would produce, but that shouldn't be a big problem.
A problem may be that it'll return false
for these failed operations and you'll have to use $this->Model->invalidFields()
to figure out what the problem was and if you can ignore it. You could override Model::save()
to do this within the model so you don't have to do it every time in the controller.
You may also want to use $this->Model->isUnique(array('guid' => $guid))
to check manually before you save. Again, you could override the save
method and have it silently return true
if the guid is not unique, but be careful with this sort of thing.