{"record":{"id":"9a0fe6028aca8b91","repo":"yiisoft/yii2","slug":"unable-to-link-models-the-link-defining-the-relat","errorCode":null,"errorMessage":"Unable to link models: the link defining the relation does not involve any primary key.","messagePattern":"Unable to link models: the link defining the relation does not involve any primary key\\.","errorType":"exception","errorClass":"yii\\base\\InvalidCallException","httpStatus":null,"severity":"error","filePath":"framework/db/BaseActiveRecord.php","lineNumber":1369,"sourceCode":"            }\n        } else {\n            $p1 = $model->isPrimaryKey(array_keys($relation->link));\n            $p2 = static::isPrimaryKey(array_values($relation->link));\n            if ($p1 && $p2) {\n                if ($this->getIsNewRecord()) {\n                    if ($model->getIsNewRecord()) {\n                        throw new InvalidCallException('Unable to link models: at most one model can be newly created.');\n                    }\n                    $this->bindModels(array_flip($relation->link), $this, $model);\n                } else {\n                    $this->bindModels($relation->link, $model, $this);\n                }\n            } elseif ($p1) {\n                $this->bindModels(array_flip($relation->link), $this, $model);\n            } elseif ($p2) {\n                $this->bindModels($relation->link, $model, $this);\n            } else {\n                throw new InvalidCallException('Unable to link models: the link defining the relation does not involve any primary key.');\n            }\n        }\n\n        // update lazily loaded related objects\n        if (!$relation->multiple) {\n            $this->_related[$name] = $model;\n        } elseif (isset($this->_related[$name])) {\n            if ($relation->indexBy !== null) {\n                if ($relation->indexBy instanceof \\Closure) {\n                    $index = call_user_func($relation->indexBy, $model);\n                } else {\n                    $index = $model->{$relation->indexBy};\n                }\n                $this->_related[$name][$index] = $model;\n            } else {\n                $this->_related[$name][] = $model;\n            }\n        }","sourceCodeStart":1351,"sourceCodeEnd":1387,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/BaseActiveRecord.php#L1351-L1387","documentation":"Error \"Unable to link models: the link defining the relation does not involve any primary key.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/BaseActiveRecord.php:1369 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"}