Update Related Models

Hi.

I have a form to create a model and 2 related models. It’s working fine but now I need to update them and I don’t know how to load the models.

On my actionCreate I made this:




$model = new ModelName;

$model2 = new RelatedModel1

$model3 = new RelatedModel2



In the actionUpload it loads the current model


$model=$this->loadModel($id);

I need to load somehow the other 2 models because it crashses when I try to update.

The relation is 1:n. Any idea?

Thanks

If you’ve correctly configured the relations between the models, you should be able to access the related models by lazy loading them on demand. The following should work:




    $model = $this->loadModel($id);

    $relatedModels1 = $model->relatedModels1;

    $relatedModels2 = $model->relatedModels2;