From c1abbc1493a18bb133221789740b33c0693403d0 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 28 Jun 2021 13:04:52 +0100 Subject: [PATCH] definitions and tidy up --- .../CreateEditRelationship.svelte | 32 ++++++------------- packages/server/src/constants/definitions.ts | 14 ++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte index 0ed5a93c0a..c653bcabf8 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte @@ -2,19 +2,14 @@ import { RelationshipTypes } from "constants/backend" import { Menu, MenuItem, MenuSection, Button, Input, Icon, ModalContent, RadioGroup, Heading } from "@budibase/bbui" - // "tasks_something": { - // "name": "tasks_something", - // "type": "link", - // "tableId": "whatever/othertable", - // "relationshipType": "one-to-many", - // }, - export let save export let datasource export let from export let tables export let relationship = {} + let originalName = relationship.name + $: console.log(relationship) $: valid = relationship.name && relationship.tableId && relationship.relationshipType $: from = tables.find(table => table._id === relationship.source) @@ -43,24 +38,15 @@ // save the relationship on to the datasource function saveRelationship() { - let key - - // find the entity on the datasource - - for (let entity in datasource.entities) { - // TODO: update with _id instead of name - if (relationship.from.name === entity) { - key = entity - } - } - - datasource.entities[key].schema[relationship.name] = { - name: relationship.name, + datasource.entities[from.name].schema[relationship.name] = { type: "link", - relationshipType: relationship.relationshipType, - tableId: relationship.to._id, - through: relationship.through + ...relationship } + if (originalName) { + // TODO: possible bug if you change name + delete datasource.entities[from.name][originalName] + } + save() } diff --git a/packages/server/src/constants/definitions.ts b/packages/server/src/constants/definitions.ts index 685c2a9824..b39f2550ab 100644 --- a/packages/server/src/constants/definitions.ts +++ b/packages/server/src/constants/definitions.ts @@ -26,3 +26,17 @@ export interface Table { primaryDisplay?: string sourceId?: string } + +export interface BudibaseAppMetadata { + _id: string + _rev?: string + appId: string + type: string + version: string + componentlibraries: string[] + name: string + url: string + instance: { _id: string } + updatedAt: Date, + createdAt: Date +} \ No newline at end of file