public function getTargetModels() { return $this->hasMany(PromocodeToItem::className(), ['promocode_id' => 'id']); }
public function actionAjaxDeleteTargetItem() { $target = Yii::$app->request->post(); $model = PromocodeToItem::find()->where(['promocode_id' => $target['data']['promocodeId'], 'item_model' => $target['data']['targetModel'], 'item_id' => $target['data']['targetModelId']])->one(); if ($model) { if ($model->delete()) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['status' => 'success']; } else { return ['status' => 'error']; } } else { return ['status' => 'success']; } }