I
I
Ivan Karabadzhak2014-04-30 00:13:18
Yii
Ivan Karabadzhak, 2014-04-30 00:13:18

Why is beforeDelete() not called when deleting via Something::model()->deleteByPk(...)?

I am using Yii version 1.
I'll give you an example. There is an Article model. Inside its beforeDelete() , I delete another entity with Category::model()->deleteByPk(...). Inside the Category, in its beforeDelete() , I similarly delete another other entity.
The fact is that there is a way to delete via Category::model->deleteByPk(...), the internal beforeDelete is no longer called.
That is, if you delete in an Article Category using deleteByPk(...), then inside the Category beforeDelete() is not called. Whatever comes up, needs to be done

$category = Category::model()->findByPk($this->route_id);
        if ($category)
        {
            $category->delete();
        }

I'm not very experienced. Is that how it's supposed to be or am I just missing something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2014-04-30
@Jakeroid

beforeDelete() only works for loaded models: Category::model()->findByPk(...)->delete();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question