Skip to content

Unable to link models #2

@FractalMind

Description

@FractalMind
$model = TENANT_device::findOne($this->FK_tenant_station_id);
if( isset($model) ) {
   $this->linkAll('tenant_device', [$model], null, false, false);
} else {
    $this->addError('FK_tenant_station_id', 'The tenant_device "' . $this->FK_tenant_station_id . '" does\'nt exists');
}

{
"name": "Exception",
"message": "Unable to link models: the models being linked cannot be newly created.",
"code": 0,
"type": "yii\base\InvalidCallException",
"file": "/var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php",
"line": 1293,
"stack-trace": [
"#0 /var/www/html/vendor/cornernote/yii2-linkall/src/LinkAllBehavior.php(87): yii\db\BaseActiveRecord->link('tenant_device', Object(common\models\tenant\TENANT_device), NULL)",
"#1 /var/www/html/vendor/cornernote/yii2-linkall/src/LinkAllBehavior.php(53): cornernote\linkall\LinkAllBehavior->link('tenant_device', 'id', Array, Array, NULL)",
"#2 [internal function]: cornernote\linkall\LinkAllBehavior->linkAll('tenant_device', Array, NULL, false, false)",
"#3 /var/www/html/vendor/yiisoft/yii2/base/Component.php(297): call_user_func_array(Array, Array)",
"#4 /var/www/html/common/models/tenant/TENANT_station.php(42): yii\base\Component->__call('linkAll', Array)",
"#5 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(545): common\models\tenant\TENANT_station->beforeSave(true)",
"#6 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(515): yii\db\ActiveRecord->insertInternal(NULL)",
"#7 /var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php(670): yii\db\ActiveRecord->insert(true, NULL)",
"#8 /var/www/html/common/gtb/db/TENANT_ActiveRecord.php(141): yii\db\BaseActiveRecord->save(true, NULL)",
"#9 /var/www/html/common/gtb/actions/CreateAction.php(51): gtb\db\TENANT_ActiveRecord->save()",
"#10 [internal function]: gtb\actions\CreateAction->run()",
"#11 /var/www/html/vendor/yiisoft/yii2/base/Action.php(94): call_user_func_array(Array, Array)",
"#12 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\Action->runWithParams(Array)",
"#13 /var/www/html/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('create', Array)",
"#14 /var/www/html/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('api2/station/cr...', Array)",
"#15 /var/www/html/vendor/yiisoft/yii2/base/Application.php(387): yii\web\Application->handleRequest(Object(yii\web\Request))",
"#16 /var/www/html/backend/web/index.php(21): yii\base\Application->run()",
"#17 {main}"
]
}

Im I doing this right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions