D
D
des1roer2015-08-21 07:49:58
Yii
des1roer, 2015-08-21 07:49:58

Yii 1 how to get returning id?

the better

$this->primaryKey = Yii::app()->getComponent($dbComponent)->getLastInsertID($this->sequence());

how
$id_analiz = Yii::app()->db->createCommand()
                        ->select("currval('a_analiz_create_id_seq1')")  //получаем ид вставленной записи
                        ->queryScalar();

or is it a matter of taste?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ErickSkrauch, 2015-09-08
@ErickSkrauch

I don’t quite understand for what purpose you are doing this, but in theory, after saving the ActiveRecord, the result of the insertion will be stored in its primirayKey (s):

$model = new Test();
$model->some_field = 'test';
$model->save();
var_dump($model->primaryKey);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question