how to create multi model form

Dear All,

I have a situation like this,

I have four tables,

  1. work_category => work is belong to a category

  2. work => the work table

  3. budget => the budget table

  4. budget_detail => contains work (one to many relationship with work)

I want to make a modelform to handle the entry of budget_detail, instead of add one detail at a time, I want user to just click a work_category, then all works belong to selected category will be displayed, so that user only need to entry the quantity. But I do not want to save all works in budget_detail. during the saving process, I will only save those that are not 0. How can I achieve this?

My current solution is to store all works as entry in budget_detail. This is becoming slow and take huge amount of database space when the work table is growing.

TIA

Daniel

Hello Daniel,

You can view your Work categories in a dropdown using any dropdown method.

Example:


<?php 

     echo $form->field($model, 'work_id')->widget(Select2::classname(), [

        'data' => $workCategoryList,

        'language' => 'en',

        'pluginOptions' => [

            'allowClear' => false,

            'placeholder' => $model->getAttributeLabel('work_id'), 

        ],

    ]); ?>

you can just add Work id and the quantity in your budget detail table. When you need it you can get the work detail from work table using work_id.