I want to achieve this: When deleting a Course, I want to find all the participant which where registered for this Course (in Register table) and put them in the Pool table.
But if you refer to idCourse in Pool’s record and then delete course record, you lose referential integrity between Pool and Course tables.
Anyway at this point, you have to put code in beforeDelete(), so:
public function beforeDelete()
{
$pool=new Pool();
$pool->idCourse=$this->idCourse;
$saveReturn = $pool->save();
if($saveReturn == false)
{
/* Uncomment next two lines if only save() new Pool record not works. */
// var_dump($pool->errors);
// exit;
}
return parent::beforeDelete();
}
If ($saveReturn = false), Pool new record has not been saved. Probably there are validation errors that you can see seeing content of errors property.