HAS MANY validation

What i want to achieve is:

  1. Generate(via gii) a form which would have a field for HAS MANY relation.

  2. Validate and save that field and save those entities into database.

I would like to know if that is though-through in Yii2 or i should make mechanism for that myself.

I think you have to implement yourself.

So no one, while developing this framework, never thought that on one page there could be more then one related entity that should be saved in one request? this just can not be true, i mean, that’s a standard task.

I think that work to implement yourself is little.

If you have new or updated related models you have an array of models.

So if you are inserting new model and related, you have:




if($model->save())

{

     foreach($arrRelated as $r)

     {

           // If you have to set reference to parent

           $r->id_parent = $model->id;

           $r->save();

     }

}



If you are only updating, you have:




if($model->save())

{

     foreach($arrRelated as $r)

     {

           $r->save();

     }

}




It’s very simple.

What i REALLY was looking for is:

http://www.yiiframework.com/wiki/666/handling-tabular-data-loading-and-validation-in-yii-2/

loadMultiple

validateMultiple