Answer the question
In order to leave comments, you need to log in
How to properly prevent deletion of an element in Yii if there are children?
Good afternoon, actually a subject.
My solution:
Before deleting, we check the tables where there may be descendants; if there are any, we return false; if there are no descendants, we return true.
The right approach?
protected function beforeDelete(){
parent::beforeDelete();
if(Places::model()->exists('metro ='.$this->id)){
return false;
}else{
return true;
}
}
Answer the question
In order to leave comments, you need to log in
If I'm not mistaken, that is, in the ActiveRecord behavoir, which will work before deletion, it is necessary to do the check in it.
instead of return true do return parent::beforeDelete();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question