hi
my tables is
-
table [work_shifts]{
id
title
}
-
table [work_shift_times]{
id
work_shift_id
title
}
-
table [work_shift_overtimes]{
id
work_shift_time_id
title
}
when i delete row in "work_shift" this make error because realtion this table with another table
my model
########work_shifts####
public function relations() {
return array(
'workShiftTimes' => array(self::HAS_MANY, 'WorkShiftTimes', 'work_shift_id'),
'workShiftOvertimes' => array(self::HAS_MANY, 'WorkShiftOvertimes', array('id'=>'workShiftTimesid'), 'through'=>'workShiftTimes'),
);
}
protected function beforeDelete()
{
WorkShiftTimes::model()->deleteAll('work_shift_id = '.$this->id);
return parent::beforeDelete();
}
########## WorkShiftTimes ######
public function relations() {
return array(
'workShiftOvertimes' => array(self::HAS_MANY, 'WorkShiftOvertimes', 'work_shift_time_id'),
'workShift' => array(self::BELONGS_TO, 'WorkShifts', 'work_shift_id'),
);
}
protected function beforeDelete()
{
WorkShiftOvertimes::model()->deleteAll('work_shift_time_id = 14');
return parent::beforeDelete();
}
##########WorkShiftOvertimes###########
public function relations() {
return array(
'workShiftTime' => array(self::BELONGS_TO, 'WorkShiftTimes', 'work_shift_time_id'),
);
}
##############
this error is view
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (erpp/work_shift_overtimes
, CONSTRAINT fk_work_shift_overtimes_work_shift_times1
FOREIGN KEY (work_shift_time_id
) REFERENCES work_shift_times
(id
) ON DELETE NO ACTION ON UPDATE NO ACT). The SQL statement executed was: DELETE FROM work_shift_times
WHERE work_shift_id = 28 (/opt/lampp/htdocs/erp/framework/db/CDbCommand.php:354)