@omnifyjp/ts 3.19.3 → 3.19.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -278,7 +278,7 @@ function generateBaseService(name, schema, reader, config) {
|
|
|
278
278
|
if (hasSoftDelete) {
|
|
279
279
|
sections.push(buildRestoreMethod(modelName, eagerLoad, eagerCount));
|
|
280
280
|
sections.push(buildForceDeleteMethod(modelName, hasTranslatable));
|
|
281
|
-
sections.push(buildEmptyTrashMethod());
|
|
281
|
+
sections.push(buildEmptyTrashMethod(hasTranslatable));
|
|
282
282
|
}
|
|
283
283
|
// ── Lookup section ────────────────────────────────────────────────────────
|
|
284
284
|
if (lookup) {
|
|
@@ -653,12 +653,32 @@ function buildForceDeleteMethod(modelName, hasTranslatable) {
|
|
|
653
653
|
}`;
|
|
654
654
|
}
|
|
655
655
|
// ── emptyTrash() ────────────────────────────────────────────────────────────
|
|
656
|
-
function buildEmptyTrashMethod() {
|
|
657
|
-
|
|
656
|
+
function buildEmptyTrashMethod(hasTranslatable) {
|
|
657
|
+
if (!hasTranslatable) {
|
|
658
|
+
return `
|
|
658
659
|
public function emptyTrash(): int
|
|
659
660
|
{
|
|
660
661
|
return $this->model::onlyTrashed()->forceDelete();
|
|
661
662
|
}`;
|
|
663
|
+
}
|
|
664
|
+
// #75 followup: query-builder forceDelete bypasses per-model logic,
|
|
665
|
+
// so translations would be orphaned. Chunk through trashed rows and
|
|
666
|
+
// delegate to forceDelete() which cascades explicitly.
|
|
667
|
+
return `
|
|
668
|
+
public function emptyTrash(): int
|
|
669
|
+
{
|
|
670
|
+
// #75 followup: delegate to per-model forceDelete so the translation
|
|
671
|
+
// cascade in forceDelete() runs. A query-builder DELETE would skip it.
|
|
672
|
+
$count = 0;
|
|
673
|
+
$this->model::onlyTrashed()->chunkById(100, function ($batch) use (&$count) {
|
|
674
|
+
foreach ($batch as $model) {
|
|
675
|
+
$this->forceDelete($model);
|
|
676
|
+
$count++;
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
return $count;
|
|
681
|
+
}`;
|
|
662
682
|
}
|
|
663
683
|
// ── lookup() ────────────────────────────────────────────────────────────────
|
|
664
684
|
function buildLookupMethod(_modelName, lookupFields, filterableFields, defaultSort) {
|