{"record":{"id":"818653a754de5c45","repo":"yiisoft/yii2","slug":"unable-to-unlink-models-the-link-does-not-involve","errorCode":null,"errorMessage":"Unable to unlink models: the link does not involve any primary key.","messagePattern":"Unable to unlink models: the link does not involve any primary key\\.","errorType":"exception","errorClass":"yii\\base\\InvalidCallException","httpStatus":null,"severity":"error","filePath":"framework/db/BaseActiveRecord.php","lineNumber":1479,"sourceCode":"                        $model->$a = null;\n                    }\n                    $model->save(false);\n                }\n            } elseif ($p1) {\n                foreach ($relation->link as $a => $b) {\n                    if (is_array($this->$b)) { // relation via array valued attribute\n                        if (($key = array_search($model->$a, $this->$b, false)) !== false) {\n                            $values = $this->$b;\n                            unset($values[$key]);\n                            $this->$b = array_values($values);\n                        }\n                    } else {\n                        $this->$b = null;\n                    }\n                }\n                $delete ? $this->delete() : $this->save(false);\n            } else {\n                throw new InvalidCallException('Unable to unlink models: the link does not involve any primary key.');\n            }\n        }\n\n        if (!$relation->multiple) {\n            unset($this->_related[$name]);\n        } elseif (isset($this->_related[$name])) {\n            /** @var ActiveRecordInterface $b */\n            foreach ($this->_related[$name] as $a => $b) {\n                if ($model->getPrimaryKey() === $b->getPrimaryKey()) {\n                    unset($this->_related[$name][$a]);\n                }\n            }\n        }\n    }\n\n    /**\n     * Destroys the relationship in current model.\n     *","sourceCodeStart":1461,"sourceCodeEnd":1497,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/BaseActiveRecord.php#L1461-L1497","documentation":"Error \"Unable to unlink models: the link does not involve any primary key.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/BaseActiveRecord.php:1479 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"}