Skip to content

Commit

Permalink
Fire beforeDelete on pivot models
Browse files Browse the repository at this point in the history
This commit tries to fix octobercms#2747
  • Loading branch information
meysammahfouzi authored Jun 29, 2018
1 parent fb2aa17 commit 2d8672d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/backend/behaviors/RelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,17 @@ public function onRelationManageRemove()
$checkedIds = $recordId ? [$recordId] : post('checked');

if (is_array($checkedIds)) {
/*
* Simulate firing beforeDelete event on pivot models
*/
foreach ($this->model->{$this->relationName} as $related) {
if (in_array($related->pivot->{$related->pivot->getOtherKey()}, $checkedIds)) {
if (method_exists($related->pivot, "beforeDelete")) {
$related->pivot->beforeDelete();
}
}
}

$foreignKeyName = $relatedModel->getKeyName();

$models = $relatedModel->whereIn($foreignKeyName, $checkedIds)->get();
Expand Down

0 comments on commit 2d8672d

Please sign in to comment.