lib/components/db/behaviors/RelatedObjects.php
public function collectModels($models = [])
    {
        if (!isset($models['relations'])) {
            $models['relations'] = [];
        }
        if ($this->owner->tabularId) {
            $models[$this->owner->tabularId] = $this->owner;
        } else {
            $models['primary'] = $this->owner;
        }
        foreach ($this->_relatedObjectsFlat as $related) {
            $models = $related->collectModels($models);
        }
        foreach ($this->_relations as $key => $relation) {
            if (!is_object($relation)) {
                if (!isset($relation['class'])) {
                    $relation['class'] = Yii::$app->classes['Relation'];
                }
                $relation = Yii::createObject($relation);
            }
            $models['relations'][$key] = $relation;
        }

        return $models;
    }
public function collectModels($models = [])
    {
        if (!isset($models['relations'])) {
            $models['relations'] = [];
        }
        if ($this->owner->tabularId) {
            $models[$this->owner->tabularId] = $this->owner;
        } else {
            $models['primary'] = $this->owner;
        }
        foreach ($this->_relatedObjectsFlat as $related) {
            $models = $related->collectModels($models);
        }
        foreach ($this->_relations as $key => $relation) {
            if (!is_object($relation)) {
                if (!isset($relation['class'])) {
                    $relation['class'] = Yii::$app->classes['Relation'];
                }
                $relation = Yii::createObject($relation);
            }
            $models['relations'][$key] = $relation;
        }

        return $models;
    }
[[@doctodo method_description:collectModels]].

@param array $models [[@doctodo param_description:models]] [optional]

@return [[@doctodo return_type:collectModels]] [[@doctodo return_description:collectModels]]