PK value not being returned

Hi,

I have long standing code that suddenly has broken after performing a composer update of yii and my vendor files.

In my controller I have

if ($flag = $model->save(false)) {
    foreach ($modelsLegs as $modelLeg) {
        $modelLeg->ProjId = $model->ProjId;
        if (!($flag = $modelLeg->save(false))) {
            $transaction->rollBack();
            return json_encode(['status' => 'Error', 'message' => 'Leg not created!']);
            break;
        }
    }

    foreach ($modelsNotes as $modelNote) {
        $modelNote->ProjId = $model->ProjId;
        if (!($flag = $modelNote->save(false))) {
            $transaction->rollBack();
            return json_encode(['status' => 'Error', 'message' => 'Note not created!']);
            break;
        }
    }
}

The model is saved and is the modelLeg, but the modelLeg->ProjId is not populated?

So the following lines are not working for some unknown reason after updating

$modelLeg->ProjId = $model->ProjId;

and

$modelNote->ProjId = $model->ProjId;

The controller has not changed in months.

Would anyone have any ideas? I’ve been staring at this code and not getting any ideas.

For full disclosure, this db is an Azure SQL Db and in this particular case the table uses a Trigger on Insert. But this was previously not an issue and ran fine for several months (even possibly over a year now) and only started to fail after updating.

Did some more testing and no other controller/table has this issues, but this is the only table that has an Insert Trigger. So something has changed that Yii no longer return the PK value from the Trigger.

I’ve put in place a workaround, far from ideal. So if anyone has any ideas, I’m all ears.

Good evening,

Can you trace what value is returned from $model->primaryKey() ?

Can you return the correct primary key by overriding this method?