public function beforeDelete() { $ret = parent::beforeDelete(); // Remove field values $this->getDb()->createCommand()->delete(TourFieldValue::tableName(), ['field_id' => $this->id])->execute(); return $ret; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TourFieldValue::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'booking_id' => $this->booking_id, 'field_id' => $this->field_id]); $query->andFilterWhere(['like', 'value', $this->value]); return $dataProvider; }
public function getFieldValues() { return $this->hasMany(TourFieldValue::className(), ['booking_id' => 'id']); }
/** * Save basic model and extra field values * @param bool|true $runValidation * @return bool */ public function save($runValidation = true) { if ($this->primaryModel->isNewRecord) { $ok = $this->primaryModel->insert($runValidation) !== false; if (!$ok) { return false; } $this->id = $this->primaryModel->id; foreach ($this as $key => $value) { if (!StringHelper::startsWith($key, $this->extra_field_prefix)) { continue; } $field_id = substr($key, strlen($this->extra_field_prefix)); $fieldValue = new TourFieldValue(); $fieldValue->field_id = $field_id; $fieldValue->booking_id = $this->primaryModel->id; $fieldValue->value = $value; $fieldValue->insert($runValidation); } } else { $ok = $this->primaryModel->update($runValidation) !== false; if (!$ok) { return false; } foreach ($this->primaryModel->fieldValues as $fieldValue) { $ok = $fieldValue->update($runValidation) !== false; if (!$ok) { return false; } } } return true; }
/** * Finds the TourFieldValue model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TourFieldValue the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TourFieldValue::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }