Fix relationship issues when creating rows

This commit is contained in:
Andrew Kingston 2023-02-28 14:56:44 +00:00
parent d2bc4d8fdc
commit 9be7d042a9
1 changed files with 20 additions and 1 deletions

View File

@ -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) {