Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Error Unable to link models: the primary key of #56

Open
Sirgalas opened this issue Nov 13, 2019 · 0 comments
Open

Error Unable to link models: the primary key of #56

Sirgalas opened this issue Nov 13, 2019 · 0 comments
Assignees

Comments

@Sirgalas
Copy link

You have an error from 384 to 386 lines.

$p1 = $model->isPrimaryKey(array_keys ($relation->link));
$p2 = $relationModel::isPrimaryKey(array_values($relation->link));
if ($relationModel->getIsNewRecord () & & $p1 && !$p2) {
...

What's the point? With such a relations

    public function getCompany()
    {
        return $this->hasOne(Company:: className (), ['id' = > 'company_id']);
    } 

if the parent class has properties primarykey (in your example on the main page Project ) the same as the relation class (in your example on the main page Company ) then your behavior will work.
But if in Project establish primaryKey as project_id the will error

Unable to link models: the primary key of ...

because relation class not save
as for me it is more correct to write the following code

$p1 = $model->isPrimaryKey(array_values($relation->link));
$p2 = $relationModel:: isPrimaryKey(array_keys($relation->link));
if ($relationModel->getIsNewRecord() && !$p1 & & $p2) {

почему так для relation
$this->hasOne(Company::className(), ['id' => 'company_id']);


array_keys($relation->link)='id'
array_values($relation->link)='company_id'
@nstCactus nstCactus self-assigned this Mar 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants