I’ll illustrate my need with an example.
There are 2 tables (2 models)
Clients: ---id ---name
Addresses: ---id ---address ---client_id
It’s a one-to-many relationship. 1 Client can have multiple Addresses.
How would I go about saving a new client and multiple addresses from one form?
[Add address button] <- when clicked new address fields pop out
user clicks again
I got one to one relationships working, but this got me confused.
My one to one Controller looks something like this:
$model = new Clients(); $model->load(Yii::$app->request->post()) && $model->save(); $model2 = new Addresses(); $model2->load(Yii::$app->request->post()); $model2->setAttribute('client_id', $model->id); $model2->save();