yii\db\ActiveQueryTrait::findWith PHP Method

findWith() public method

Finds records corresponding to one or multiple relations and populates them into the primary models.
public findWith ( array $with, array | ActiveRecord[] &$models )
$with array a list of relations that this query should be performed with. Please refer to [[with()]] for details about specifying this parameter.
$models array | ActiveRecord[] the primary models (can be either AR instances or arrays)
    public function findWith($with, &$models)
    {
        $primaryModel = reset($models);
        if (!$primaryModel instanceof ActiveRecordInterface) {
            $primaryModel = new $this->modelClass();
        }
        $relations = $this->normalizeRelations($primaryModel, $with);
        /* @var $relation ActiveQuery */
        foreach ($relations as $name => $relation) {
            if ($relation->asArray === null) {
                // inherit asArray from primary query
                $relation->asArray($this->asArray);
            }
            $relation->populateRelation($name, $models);
        }
    }