S
S
Sergey Bard2018-07-27 10:36:29
Yii
Sergey Bard, 2018-07-27 10:36:29

How to disable afterFind?

Hello everyone, there is a problem with query optimization, I made a custom variable in the afterFind method in the Profile model

public function afterFind()
{
        $this->projectGroup = $this->projectGroups;
  return;
}

$this->projectGroups - a method that receives data from related tables through hasMany, so I made such a custom variable because I need some additional data when saving or updating, but the problem is that when I do it just to display some data through the GridView and I make a call through the links to the field from the Profile model, then this $this->projectGroup variable also works because afterFind is triggered and eventually the page loads for a long time and the debug shows thousands of requests that are associated with this variable, but
I don’t need it here , so is it possible to somehow say that afterFind works only in the place I need and that's it, in order
to exclude requests that I don't need?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2018-07-27
@serg_small_developer

Remove assignment in afterFind.
Hang the script on the afterFind event in the right place, and implement the assignment in it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question