From 9be7d042a934090c56df6dab205b612fb1a34c20 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 28 Feb 2023 14:56:44 +0000 Subject: [PATCH] Fix relationship issues when creating rows --- .../src/components/sheet/stores/rows.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/sheet/stores/rows.js b/packages/frontend-core/src/components/sheet/stores/rows.js index 1396b5f753..c49da287a7 100644 --- a/packages/frontend-core/src/components/sheet/stores/rows.js +++ b/packages/frontend-core/src/components/sheet/stores/rows.js @@ -100,7 +100,26 @@ export const createRowsStore = context => { // Adds a new empty row const addRow = async () => { try { - const newRow = await API.saveRow({ tableId: get(tableId) }) + // Create row + let newRow = await API.saveRow({ tableId: get(tableId) }) + + // Use search endpoint to fetch the row again, ensuring relationships are + // properly enriched + const res = await API.searchTable({ + tableId: get(tableId), + limit: 1, + query: { + equal: { + _id: newRow._id, + }, + }, + paginate: false, + }) + if (res?.rows?.[0]) { + newRow = res.rows[0] + } + + // Update state handleNewRows([newRow]) return newRow } catch (error) {