既存の検証ルールを使用して、関係が満たされていることを確認しようとしています (つまり、テーブル EventOther の event_id がテーブル Event に存在します)。私は(EventOther.php)を使用しようとしています
    public function rules(){
        return array(
                array('event_id','exists','allowEmpty'=>false,
                        'attributeName'=>'id','className'=>'Event',
                        'message'=>'Specified event does not exist. (event_id incosistent)')
    );
データベースに新しいエントリを作成します (ID 17 のレコードは存在しません)。
    $ev = new EventOther;
    $ev->event_id = 17;
    $ev->location_id = 1;
    $ev->location = "Test Location - hardcoded";
    if(!$ev->save()) print_r($ev->getErrors());
これは常に CDbException になります。
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 (`fiss`.`event_other`, CONSTRAINT `event_other_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `event` (`id`)). The SQL statement executed was: INSERT INTO `event_other` (`event_id`, `location_id`, `location`) VALUES (:yp0, :yp1, :yp2)
$ev->event_idさらに、が設定されていない場合でも、検証は合格し'allowEmpty'=>falseます。
Event::model()->exists("id=2");(ID 2 のレコードが存在する場所) は 1 をEvent::model()->exists("id=17");返し、空を返します。
CExistValidator を誤解/誤用しましたか? すべての助けに感謝します。