Paste ignore function?
Is there a way to make "paste ignore" in the cake without using the model-> query function?
$this->Model->save(array( 'id' => NULL, 'guid' => $guid, 'name' => $name, )); Generates an error:
Warning (512): SQL Error: 1062: Duplicate entry 'GUID.....' for key 'unique_guid' [CORE/cake/libs/model/datasources/dbo_source.php, line 524] It would be great if you set some flag or parameter that says βdon't careβ
This is not really an INSERT IGNORE solution, but you must use validation rules to handle this situation at the application level. If you simply attach the isUnique ( 2.x ) ( 3.x ) validation rule to the isUnique field in your model, Cake will automatically exit the save operation if the manual already exists.
Behind the scenes, he will make two queries in the database instead of creating INSERT IGNORE , but this should not be a big problem.
The problem may be that it will return false for these failed operations, and you will have to use $this->Model->invalidFields() to find out what the problem is, and if you can ignore it. You can override Model::save() to do this in the model, so you do not need to do this every time in the controller.
You can also use $this->Model->isUnique(array('guid' => $guid)) ( 2.x ) ( 3.x ) to manually check before saving. Again, you can override the save method and make it silently return true if guid is not unique, but be careful with such things.
I donβt think CakePHP has such a simple flag or parameter, since this warning was originally generated by MySql, and not by itself. If you do not need a unique function on guid , you need to make a request to change the index .Eg
$this->Model->query("ALTER TABLE `yourdatebasename`.`yourtablename` DROP INDEX `guid` ,ADD INDEX `guid` ( `guid` )");