From 448b0ca2ae6f6e371624574d6be37240d8d92d04 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 12 Oct 2020 14:14:50 +0100 Subject: [PATCH] Replace bindings to link fields with new count runtime property --- .../builderStore/fetchBindableProperties.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/builderStore/fetchBindableProperties.js b/packages/builder/src/builderStore/fetchBindableProperties.js index 9205a3cad3..5aa9e47f98 100644 --- a/packages/builder/src/builderStore/fetchBindableProperties.js +++ b/packages/builder/src/builderStore/fetchBindableProperties.js @@ -95,15 +95,23 @@ const contextToBindables = (models, walkResult) => context => { return [] } - const newBindable = ([key, fieldSchema]) => ({ - type: "context", - fieldSchema, - instance: context.instance, - // how the binding expression persists, and is used in the app at runtime - runtimeBinding: `${contextParentPath}data.${key}`, - // how the binding exressions looks to the user of the builder - readableBinding: `${context.instance._instanceName}.${model.name}.${key}`, - }) + const newBindable = ([key, fieldSchema]) => { + // Replace link bindings with a new property representing the count + let runtimeBoundKey = key + if (fieldSchema.type === "link") { + runtimeBoundKey = `${key}_count` + } + + return { + type: "context", + fieldSchema, + instance: context.instance, + // how the binding expression persists, and is used in the app at runtime + runtimeBinding: `${contextParentPath}data.${runtimeBoundKey}`, + // how the binding expressions looks to the user of the builder + readableBinding: `${context.instance._instanceName}.${model.name}.${key}`, + } + } return ( Object.entries(schema)