D
D
Denis Labutin2015-04-14 16:05:42
Yii
Denis Labutin, 2015-04-14 16:05:42

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

2 answer(s)
A
Alexander, 2015-04-14
@wiggle

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.

M
Maxim Grechushnikov, 2015-04-14
@maxyc_webber

instead of return true do return parent::beforeDelete();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question