yii\db\ActiveRelationTrait::findFor PHP Method

findFor() public method

This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion.
public findFor ( string $name, yii\db\ActiveRecordInterface | BaseActiveRecord $model ) : mixed
$name string the relation name
$model yii\db\ActiveRecordInterface | BaseActiveRecord the primary model
return mixed the related record(s)
    public function findFor($name, $model)
    {
        if (method_exists($model, 'get' . $name)) {
            $method = new \ReflectionMethod($model, 'get' . $name);
            $realName = lcfirst(substr($method->getName(), 3));
            if ($realName !== $name) {
                throw new InvalidParamException('Relation names are case sensitive. ' . get_class($model) . " has a relation named \"{$realName}\" instead of \"{$name}\".");
            }
        }
        return $this->multiple ? $this->all() : $this->one();
    }