@@ -193,7 +193,7 @@ protected function getMorphManyData($relation, $foreignKeyIds)
193
193
}
194
194
195
195
/**
196
- * Execute delete, or restore.
196
+ * Execute delete or restore or forcedelete .
197
197
*
198
198
* @param Illuminate\Database\Eloquent\Relations\Relation $relation
199
199
* @param string $foreignKey
@@ -211,7 +211,13 @@ protected function execute($relation, $foreignKey, $foreignKeyIds, $affectedRows
211
211
$ relationModel = $ relationModel ->whereIn ($ foreignKey , $ foreignKeyIds )->limit ($ affectedRows );
212
212
213
213
$ this ->run ($ relationModel ->get ([$ relationModel ->getModel ()->getKeyName ()]));
214
- $ relationModel ->{$ this ->direction }($ this ->directionData );
214
+
215
+ // COMMIT : force delete when parent model "isForceDeleting = true"
216
+ if ($ this ->isForceDeleting ($ relation )) {
217
+ $ relationModel ->forceDelete ();
218
+ } else {
219
+ $ relationModel ->{$ this ->direction }($ this ->directionData );
220
+ }
215
221
}
216
222
}
217
223
@@ -251,7 +257,12 @@ protected function validateRelation($model, $relation)
251
257
protected function affectedRows ($ relation , $ foreignKey , $ foreignKeyIds )
252
258
{
253
259
$ relationModel = $ relation ->getQuery ()->getModel ();
254
- $ relationModel = $ this ->withTrashed ($ relationModel ::query ());
260
+ $ relationModel = new $ relationModel ();
261
+
262
+ // COMMIT : retreive relation trashed items when parent model "isForceDeleting = true"
263
+ if ($ this ->direction !== 'delete ' || $ this ->isForceDeleting ($ relation )) {
264
+ $ relationModel = $ relationModel ->withTrashed ();
265
+ }
255
266
256
267
return $ relationModel ->whereIn ($ foreignKey , $ foreignKeyIds )->count ();
257
268
}
@@ -291,4 +302,15 @@ protected function withTrashed(Builder $builder): Builder
291
302
292
303
return $ builder ;
293
304
}
305
+
306
+ /**
307
+ * COMMIT
308
+ * Check if parent has a force delete enabled
309
+ * @return boolean
310
+ */
311
+ protected function isForceDeleting ($ relation )
312
+ {
313
+ $ parent = $ relation ->getParent ();
314
+ return property_exists ($ parent , 'forceDeleting ' ) && $ parent ->isForceDeleting ();
315
+ }
294
316
}
0 commit comments