I
I
Iossarian2019-04-08 10:33:12
Yii
Iossarian, 2019-04-08 10:33:12

How to get LastInsertID() from a specific user?

Good afternoon. The table has an auto-increment field that is unique for each user - this is the contract number, which for each new contract must be incremented by 1, regardless of the contract numbers of other users. Tell me, is there any tool in yii2 that allows you to pull LastInsertID () from a specific user? If on fingers, then something like LastInsertID()->where('user-id' => $id); Or is there a better way to implement this functionality?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2019-04-08
@Iossarian

$lastUserId = Model::find()->orderBy(['id' => SORT_DESC])->where(['user-id' => $id])->one()->id;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question