Это то, что я использую для подавления дубликатов на 1.3:
Файл: app / 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;
}
}