@@ -407,9 +407,9 @@ private function replace(array $data, array $original, array $deleteIds = [])
407407 private function delete ($ ids = [])
408408 {
409409 foreach ($ ids as $ table => $ deleteColumns ) {
410- foreach ($ deleteColumns as $ deletion => $ primaries ) {
410+ foreach ($ deleteColumns as $ deletion => $ deletionContext ) {
411411 // Arrange values into groups based on all but the last key
412- $ grouped = Collection::group ($ primaries , function ($ keys ) {
412+ $ grouped = Collection::group ($ deletionContext [ ' keys ' ] , function (array $ keys ) {
413413 array_pop ($ keys );
414414 return implode (': ' , $ keys );
415415 });
@@ -453,7 +453,17 @@ private function delete($ids = [])
453453
454454 $ query ->closeOr ();
455455
456- $ result = $ deletion ? $ query ->isNull ($ deletion )->update ([$ deletion => gmdate ('Y-m-d H:i:s ' )]) : $ query ->remove ();
456+ if ($ deletion ) {
457+ $ result = $ query
458+ ->isNull ($ deletion )
459+ ->update (array_merge (
460+ [$ deletion => gmdate ('Y-m-d H:i:s ' )],
461+ $ deletionContext ['data ' ]
462+ ));
463+ } else {
464+ $ result = $ query ->remove ();
465+ }
466+
457467 if (!$ result ) {
458468 throw new \Exception ('Failed to delete records. ' );
459469 }
@@ -468,21 +478,26 @@ private function delete($ids = [])
468478 *
469479 * @param array $data
470480 * @param array $list
471- * @return array
481+ * @return array<string, array<string, array{
482+ * keys: list<array<string, mixed>>,
483+ * data: array<string, mixed>
484+ * }>>
472485 */
473486 private function collectPrimary (array $ data = [], $ list = [])
474487 {
475488 $ table = $ this ->definition ->getTable ();
476489 $ primaryKey = $ this ->definition ->getPrimaryKey ();
477490 $ deletion = $ this ->definition ->getDeletionTimestamp ();
491+ $ deletionData = $ this ->definition ->getDeletionData ();
478492
479493 $ item = [];
480494
481495 foreach ($ primaryKey as $ column ) {
482496 $ item [$ column ] = $ data [$ column ];
483497 }
484498
485- $ list [$ table ][$ deletion ][] = $ item ;
499+ $ list [$ table ][$ deletion ]['keys ' ][] = $ item ;
500+ $ list [$ table ][$ deletion ]['data ' ] = $ deletionData ;
486501
487502 foreach ($ this ->definition ->getProperties () as $ property ) {
488503 $ values = $ data [$ property ->getName ()] ?? [];
0 commit comments