I have some normalized tables with one junction table. First of all my tender_post is created. After this the next table tender_project.
"tender_post"s field ‘id’ is auto_increment so it is set automatically by saving. Now I need this id for the next saving in the same form for tender_project. I could do this with another query:
Once you do a $model->save() the generated id is stored in the $modle variable so just read it form it.
just to be more clear
public function actionCreate()
{
$post = new tenderPost;
if ($post->load(Yii::$app->request->post()) && $post->save()) {
$project= new tenderProject;
$project->id_post=$post->id_post;
........
To this there are exception for those database that does not support last_insert_id (i.e. oracle) but if you use mysql it works.