1
cakephp에 "insert ignore"를 설정하는 방법이 있습니까? Model-> query();를 사용하고 싶지 않습니다. 다른 방법이 있습니까?cakephp에서 "중복 입력"오류를 제거하거나 관리하십시오.
파일 : 응용 프로그램/app_model.php
/**
*
* Callback executed when a save has failed.
* Contains database error parsing and evaluation to display appropriate messages to end-users.
*
*/
private function afterSaveFailed() {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$lastError = $db->lastError();
// this holds the match for the key id
// add more for more database types
$dupe_check=array(
'mysql' => '/^\d+: Duplicate entry \'.*\' for key (\d+)$/i',
'postgres' => '/^ERROR: duplicate key value violates .+ "(.+)"$/i',
);
// this holds the match for the key id
// add more for more database types
$foreign_check=array(
'postgres' => '/^ERROR: insert or update on table "(.+)" violates foreign key constraint .+/i',
);
if(preg_match($dupe_check[$db->config['driver']], $lastError, $matches)
&& !empty($dupe_check[$db->config['driver']])) {
$matches[1] = str_replace('_key','',$matches[1]);
$matches[1] = str_replace($this->table.'_','',$matches[1]);
$this->invalidate('db','Error: Duplicate value found.');
return;
}
if(preg_match($foreign_check[$db->config['driver']], $lastError, $matches)
&& !empty($foreign_check[$db->config['driver']])) {
$this->invalidate('db','Error: Referenced value not found.');
return;
}
}
http://stackoverflow.com/questions/2830808/cakephp-insert-ignore- –
감사합니다. 찾지 못했습니다. – Chobeat