/** * Creates a new Store model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $coordinate = new Coordinate(); $store = new Store(); if ($coordinate->load(Yii::$app->request->post()) && $coordinate->validate() && $store->load(Yii::$app->request->post()) && $store->validate()) { $transaction = Yii::$app->db->beginTransaction(); try { $coordinate->save(false); $store->coordinate_id = $coordinate->id; $store->save(false); $transaction->commit(); return $this->redirect(['view', 'id' => $store->id]); } catch (Exception $e) { $transaction->rollBack(); } } return $this->render('create', ['coordinate' => $coordinate, 'store' => $store]); }
public function getCoordinate() { return $this->hasOne(Coordinate::className(), ['id' => 'coordinate_id']); }