I have a problem validating the existence of a foreign key:
Table countries
* country_code varchar(2) (pk)
* country_name varchar(64)
* country_currency char(3) (fk->currencies.currency_code)
Table currencies
* currency_code char(3) (pk)
* currency_name varchar(32)
Model Countries.php
public function rules()
{
return array(
// other validation rules
array('country_currency', 'length', 'is'=>3),
array('country_currency', 'match', 'pattern'=>'/[A-Z]{3}/', 'message'=>'Uppercase alphabetic only!'),
array('country_currency', 'exists',
'attributeName'=>'currency_code',
'className'=>'application.models.Currencies',
'skipOnError',
'message'=>'Currency must be already defined!'),
// other validation rules
}
Upon saving the country with a non existing currency it explodes with the following error:
CDbException Description CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mpldb/countries`, CONSTRAINT `fk_countries_currencies` FOREIGN KEY (`country_currency`) REFERENCES `currencies` (`currency_code`) ON DELETE NO ACTION ON UPDATE NO ACTION)
What am I doing wrong? All I want is my error message displayed. Thanks for the help.

Help















