yiisoft/yii2 · error · yii\base\InvalidCallException

Unable to unlink models: the link does not involve any prima

Error message

Unable to unlink models: the link does not involve any primary key.

What it means

Error "Unable to unlink models: the link does not involve any primary key." thrown in yiisoft/yii2.

Source

Thrown at framework/db/BaseActiveRecord.php:1479

                        $model->$a = null;
                    }
                    $model->save(false);
                }
            } elseif ($p1) {
                foreach ($relation->link as $a => $b) {
                    if (is_array($this->$b)) { // relation via array valued attribute
                        if (($key = array_search($model->$a, $this->$b, false)) !== false) {
                            $values = $this->$b;
                            unset($values[$key]);
                            $this->$b = array_values($values);
                        }
                    } else {
                        $this->$b = null;
                    }
                }
                $delete ? $this->delete() : $this->save(false);
            } else {
                throw new InvalidCallException('Unable to unlink models: the link does not involve any primary key.');
            }
        }

        if (!$relation->multiple) {
            unset($this->_related[$name]);
        } elseif (isset($this->_related[$name])) {
            /** @var ActiveRecordInterface $b */
            foreach ($this->_related[$name] as $a => $b) {
                if ($model->getPrimaryKey() === $b->getPrimaryKey()) {
                    unset($this->_related[$name][$a]);
                }
            }
        }
    }

    /**
     * Destroys the relationship in current model.
     *

View on GitHub (pinned to 66f00d18a2)

When it happens

Trigger: Thrown at framework/db/BaseActiveRecord.php:1479 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17). Data as JSON: /api/errors/818653a754de5c45. Report an issue: GitHub.