M
M
Michael2019-07-29 22:16:25
Yii
Michael, 2019-07-29 22:16:25

Why does the error occur - Unable to link models: the primary key of app\models is null?

Hello everybody! I'm trying to link two tables Accept and Address. In the Accept controller in the Create action, I wrote the following:

$model = new Accept();
$model->link('address', new Address());

But an error occurs:
Unable to link models: the primary key of app\models\Accept is null.

Relationship between tables set to
Accept model
public function getAddress(){
        return $this->hasOne(Address::className(), ['accept_id' => 'id']);
}

address model
public function getAccepts(){
         return $this->hasMany(Accept::className(), ['id' => 'accept_id']);
}

The error says that the primary key of the Accept model is null, but it doesn't seem to be true, or I just don't see the obvious
5d3f45f462b66573364424.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-07-29
@Bally

Goodnight.
I think you didn't fully understand how link();
Here is the documentation , and here is a quote from the documentation.
You, as I understand it, just this case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question