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?