B
B
Boris Yakushev2017-01-04 18:10:42
Yii
Boris Yakushev, 2017-01-04 18:10:42

Yii2 getting id before insert?

Good afternoon.
Tell me, please, is it possible to somehow get the id of the record before inserting the record into the table?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2017-01-04
@za4me

Postgre cannot be used for mysql
: stackoverflow.com/a/39509170/1603055

A
Alexander Smirnov, 2017-01-04
@ap0stal

In yii2 to save related models use $this->id in ActiveRecord.afterSave() which will be used in child objects.

public function afterSave($insert, $changedAttributes)
{
        parent::afterSave($insert, $changedAttributes);
        // $this->id уже содержит A/I ID записи 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question