From 10ac216964dca0a4969b103abc9fb27dcc58df10 Mon Sep 17 00:00:00 2001 From: zipg Date: Wed, 2 Sep 2026 11:18:44 +0800 Subject: [PATCH] fix(grid): allow deleting rows from DISTINCT join results --- apps/desktop/src/stores/queryStore.ts | 6 +++++- packages/app-tests/queryStore.test.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts index e54dd2b10d..a286bd5761 100644 --- a/apps/desktop/src/stores/queryStore.ts +++ b/apps/desktop/src/stores/queryStore.ts @@ -4432,7 +4432,11 @@ export const useQueryStore = defineStore("query", () => { const queryAnalysis = { ...target.analysis, ...(target.analysis.distinct && canInsertIntoEditableQuerySource(tab, dbType as DatabaseType, target, target.sourceColumns) ? { allowInsert: true } : {}), - allowDelete: !target.analysis.distinct, + // A DISTINCT result is still one-to-one with the selected source row + // when that source's complete primary key is present in the projection. + // The candidate filter above guarantees that identity before enabling + // the primary-key based delete SQL. + allowDelete: true, allowInsertDelete: false, multiSource: true, }; diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.ts index 47ab2e7a45..ad7d3f271a 100644 --- a/packages/app-tests/queryStore.test.ts +++ b/packages/app-tests/queryStore.test.ts @@ -3438,7 +3438,7 @@ test("binds DISTINCT qualified-star edits to the single safe joined source", asy assert.equal(tab?.queryAnalysis?.multiSource, true); assert.equal(tab?.queryAnalysis?.distinct, true); assert.equal(tab?.queryAnalysis?.allowInsert, true); - assert.equal(tab?.queryAnalysis?.allowDelete, false); + assert.equal(tab?.queryAnalysis?.allowDelete, true); assert.equal(tab?.queryAnalysis?.allowInsertDelete, false); assert.equal(tab?.tableMeta?.tableName, "users"); assert.deepEqual(tab?.querySourceColumns, ["id", "name"]);