Hey, I want to check ForeignKey before save, if data is not in the foreign table then get an error message. Can anyone help me how to do that?
here is the relation
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'role' => array(self::BELONGS_TO, 'Role', 'Role_id'),
);
}
public function create()
{
if(!isset($this->Role_id)) {
$this->addError('', 'Role is not set');
} else {
$this->Role_id = $this->role->id;
}
$this->save();
}
----
$this->Role_id = $this->role->id;
this is not working. Am I wrong?
Page 1 of 1
Check Foreign Key before save
#2
Posted 17 May 2010 - 09:07 AM
You can use a CRequiredValidator instead of checking it, and for the value in the foreign table you can use a CExistValidator
Share this topic:
Page 1 of 1

Help













