Hey y’all,
Situation:
1 page were i make an parrent model($parent) and can make many child models($child)
This by doing an create on the $parent and adding custom code to the validation.
public function actionCreate()
{
$parent = new Parent();
if ($parent->load(Yii::$app->request->post())) {
$parent->save();
foreach($_POST['child'] as $child-information){
$child = new Child();
$child->information = $child-information;
$model->link("childs", $quest);
}
return $this->redirect(['view', 'id' => $parent->id]);
} else {
return $this->render('create',[
'ParentModel' => $parent,
]
);
}
}
this code will give me an Unable to link models: the primary key is null.
Thnx in Advance!