diff --git a/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte b/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte index 85d57e665a..ee9fd12c0c 100644 --- a/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte +++ b/packages/builder/src/components/automation/SetupPanel/RowSelectorTypes.svelte @@ -157,7 +157,7 @@ {:else if schema.type === "link"} onChange({ @@ -169,7 +169,7 @@ /> {:else if schema.type === "bb_reference" || schema.type === "bb_reference_single"} diff --git a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte index b012766171..745f29d56a 100644 --- a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte +++ b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte @@ -146,7 +146,7 @@ {:else if type === "link"} (value = e.detail)} /> diff --git a/packages/builder/src/components/common/LinkedRowSelector.svelte b/packages/builder/src/components/common/LinkedRowSelector.svelte index 8db4a7dc03..dc094bc1ab 100644 --- a/packages/builder/src/components/common/LinkedRowSelector.svelte +++ b/packages/builder/src/components/common/LinkedRowSelector.svelte @@ -6,7 +6,7 @@ import { createEventDispatcher } from "svelte" export let schema - export let linkedRows = [] + export let linkedData export let useLabel = true export let linkedTableId export let label @@ -15,14 +15,25 @@ let rows = [] let linkedIds = [] - $: linkedIds = (Array.isArray(linkedRows) ? linkedRows : [])?.map( - row => row?._id || row - ) + $: fieldValue = getFieldValue(linkedData) $: label = label || capitalise(schema.name) $: linkedTableId = linkedTableId || schema.tableId $: linkedTable = $tables.list.find(table => table._id === linkedTableId) $: fetchRows(linkedTableId) + const getFieldValue = val => { + const linkedIds = (Array.isArray(val) ? val : [])?.map( + row => row?._id || row + ) + if (schema.relationshipType === "one-to-many") { + return linkedIds?.[0] + } else if (schema.type === "bb_reference_single") { + return val + } else { + return linkedIds + } + } + async function fetchRows(linkedTableId) { try { rows = await API.fetchTableData(linkedTableId) @@ -45,7 +56,7 @@ {:else if schema.relationshipType === "one-to-many" || schema.type === "bb_reference_single"}