Yii2: cannot get primary key after $model->save()

Created on 23 Feb 2014  路  3Comments  路  Source: yiisoft/yii2

After call $model->save();
and i tried to get the last INSERT record id via $model->[PRIMARY KEY NAME]

but the return is just empty string ''

I think it might be a bug.

Most helpful comment

$model->getPrimaryKey();

see get first

All 3 comments

i also did tried $model->primaryKey but it still got the empty string.

The weird thing is that other model is work just fine...

I check the database structure already and that table has set primary key with auto incremental...

Okay, it's because there has primary key field in the rules... after remove that, it works now

$model->getPrimaryKey();

see get first

Was this page helpful?
0 / 5 - 0 ratings