{"record":{"id":"f9b6b4c25a0bed2c","repo":"yiisoft/yii2","slug":"class-has-no-relation-named-name","errorCode":null,"errorMessage":"{class} has no relation named \"{name}\".","messagePattern":"(.+?) has no relation named \"(.+?)\"\\.","errorType":"exception","errorClass":"yii\\base\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/BaseActiveRecord.php","lineNumber":1262,"sourceCode":"    /**\n     * Returns the relation object with the specified name.\n     * A relation is defined by a getter method which returns an [[ActiveQueryInterface]] object.\n     * It can be declared in either the Active Record class itself or one of its behaviors.\n     * @param string $name the relation name, e.g. `orders` for a relation defined via `getOrders()` method (case-sensitive).\n     * @param bool $throwException whether to throw exception if the relation does not exist.\n     * @return ActiveQueryInterface|ActiveQuery|null the relational query object. If the relation does not exist\n     * and `$throwException` is `false`, `null` will be returned.\n     * @throws InvalidArgumentException if the named relation does not exist.\n     */\n    public function getRelation($name, $throwException = true)\n    {\n        $getter = 'get' . $name;\n        try {\n            // the relation could be defined in a behavior\n            $relation = $this->$getter();\n        } catch (UnknownMethodException $e) {\n            if ($throwException) {\n                throw new InvalidArgumentException(get_class($this) . ' has no relation named \"' . $name . '\".', 0, $e);\n            }\n\n            return null;\n        }\n        if (!$relation instanceof ActiveQueryInterface) {\n            if ($throwException) {\n                throw new InvalidArgumentException(get_class($this) . ' has no relation named \"' . $name . '\".');\n            }\n\n            return null;\n        }\n\n        if (method_exists($this, $getter)) {\n            // relation name is case sensitive, trying to validate it when the relation is defined within this class\n            $method = new \\ReflectionMethod($this, $getter);\n            $realName = lcfirst(substr($method->getName(), 3));\n            if ($realName !== $name) {\n                if ($throwException) {","sourceCodeStart":1244,"sourceCodeEnd":1280,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/BaseActiveRecord.php#L1244-L1280","documentation":"Error \"{class} has no relation named \"{name}\".\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/BaseActiveRecord.php:1262 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}