I have "components" that I make relation between them , and if I want to "update" the information about some component related to other,I must delete the related "component" and the relation

. In actionUpdate I have :
public function actionUpdate($id) {
$model = Component::find()->where(['id' => $id])->one();
$tractorModels = ArrayHelper::map(Tractormodel::find()->all(), 'id', 'model');
$components = Component::find()->all();
$depModels = Dependency::find()->where(['component_id' => $id])->all();
$deletedIDs = Yii::$app->request->post("deletedIds");
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$dependendComponents = Yii::$app->request->bodyParams['ids'];
foreach ($dependendComponents as $dComp) {
$dependencyModel = new Dependency();
$dependencyModel->setAttributes([
'count' => $dComp['quantity'],
'component_id' => $model->id,
'dependent_id' => $dComp['id']
]);
$dependencyModel->save();
}
if ($deletedIDs && is_array($deletedIDs)) {
Dependency::deleteAll(['id' => Yii::$app->request->post()["deletedIds"]]);
}
return $this->redirect(['index', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model, 'tractorModels' => $tractorModels,
'components' => $components, 'depModels' => $depModels,
]);
}
}
and in the view I use jQuery to get the deleted items in array with id (deletedIDs) , and to delete the relation and related "items" to the components
wrapper.on("click", ".remove_field", function (e) {
var wantedDiv = $(this).parent('div').children().first();
var selectTag = $(wantedDiv).find('select');
var clickedId = $(selectTag).find('[selected=""]').attr('value');
var deletedIdsArray = $('#deletedIDs');
console.log($('#deletedIDs'));
if (clickedId) {
$('#deletedIds').append('<input type="hidden" name="deletedIds[]" value="' + clickedId + '">');
}
e.preventDefault();
$(this).parent('div').remove();
x--;
});
Everything is ok on "theory" but the components dont delete in the DB , I look if
if ($deletedIDs && is_array($deletedIDs)) {
Dependency::deleteAll(['IN', 'id', $deletedIDs]);
}
work , and I var_dump($deletedIDs) and got the array with the items I want to delete,but the components that are related to the "item" when I delete them don`t disappear. Can someone tell me what I miss ?
deleteAllmethod works fine to me (is array and contains multiple IDs. So it probably works in your case, too). What you can try is to usetryand get exceptions (to see what's wrong).t delete them in the Database , var_dump work , and it seems to catch them and going to delete them , but actually dont delete them , and thats a bit acquard ( here is my var_dump with all elements I want to delete , so I think I miss something but cant figure out what) . And yes , the array cointains every ID from each "component" I want to delete . array(3) { [0]=> string(2) "15" [1]=> string(2) "13" [2]=> string(2) "16" }