Yii2 afterFind() on empty result
<p>I overloaded in one of my models the afterFind() function:</p>

<pre><code>public function afterFind()
{
    parent::afterFind();
    echo "&lt;PRE&gt;";
    echo var_dump($this);
    echo "&lt;/PRE&gt;";
    die();
}
</code></pre>

<p>I get the dump in case that the query result is NOT empty.</p>

<p>But this is not getting called in case that the query that gets executed returns no result.</p>

<p>I need to call it especially in the case that no result is found to try to load the requested data via a different source then.</p>

<p>How can i achieve this?</p>

<p>[EDIT]</p>

<p>Find gets called by:</p>

<pre><code>return $this-&gt;hasOne(Myclass::className(), ['id' =&gt; 'key_id']);
</code></pre>

<p>since hasOne(...) uses </p>

<pre><code>public function hasOne($class, $link)
{
    /* @var $class ActiveRecordInterface */
    /* @var $query ActiveQuery */
    $query = $class::find();
    $query-&gt;primaryModel = $this;
    $query-&gt;link = $link;
    $query-&gt;multiple = false;
    return $query;
}
</code></pre>