client_firm(id,name,inn)
client_face(id,name1,name2,name3,phone)
client_face_x_client_firm(id, client_face_id,client_firm_id) с внешними ключами
В моделях есть связи:
ClientFace
Код: Выделить всё
public function getFaceFirms()
{
return $this->hasMany(ClientFaceXClientFirm::className(), ['client_face_id' => 'id']);
}
public function getFirms()
{
return $this->hasMany(ClientFirm::className(), ['id' => 'client_firm_id'])->via('faceFirms');
}
Код: Выделить всё
public function getFirm()
{
return $this->hasOne(ClientFirm::className(), ['id' => 'client_firm_id']);
}
public function getFace()
{
return $this->hasOne(ClientFace::className(), ['id' => 'client_face_id']);
}
FaceController
Код: Выделить всё
public function actionCreate()
{
$model = new ClientFace();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}