yii\db\ActiveRelationTrait::addInverseRelations PHP Method

addInverseRelations() private method

If applicable, populate the query's primary model into the related records' inverse relationship
Since: 2.0.9
private addInverseRelations ( array &$result )
$result array the array of related records as generated by [[populate()]]
    private function addInverseRelations(&$result)
    {
        if ($this->inverseOf === null) {
            return;
        }
        foreach ($result as $i => $relatedModel) {
            if ($relatedModel instanceof ActiveRecordInterface) {
                if (!isset($inverseRelation)) {
                    $inverseRelation = $relatedModel->getRelation($this->inverseOf);
                }
                $relatedModel->populateRelation($this->inverseOf, $inverseRelation->multiple ? [$this->primaryModel] : $this->primaryModel);
            } else {
                if (!isset($inverseRelation)) {
                    $inverseRelation = (new $this->modelClass())->getRelation($this->inverseOf);
                }
                $result[$i][$this->inverseOf] = $inverseRelation->multiple ? [$this->primaryModel] : $this->primaryModel;
            }
        }
    }