Fix for saving relationships that have the same field name used on both sides, previously this could cause a relationship to be cleared depending on how the relationship schema was configured. There is a chance when saving that this won't happen as which side of the relationship is denoted by doc1 and doc2 is random, so when this happens is random. Using the table to pick the correct side is safer than just using the field name.

This commit is contained in:
mike12345567 2023-11-29 18:45:48 +00:00
parent 5ac30510c6
commit b86640772b
2 changed files with 17 additions and 5 deletions

View File

@ -24,7 +24,7 @@ import AWS from "aws-sdk"
import fs from "fs" import fs from "fs"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import * as pro from "@budibase/pro" import * as pro from "@budibase/pro"
import { App, Ctx, ProcessAttachmentResponse, Upload } from "@budibase/types" import { App, Ctx, ProcessAttachmentResponse } from "@budibase/types"
const send = require("koa-send") const send = require("koa-send")
@ -212,7 +212,9 @@ export const serveBuilderPreview = async function (ctx: Ctx) {
if (!env.isJest()) { if (!env.isJest()) {
let appId = context.getAppId() let appId = context.getAppId()
const previewHbs = loadHandlebarsFile(`${__dirname}/preview.hbs`) const templateLoc = join(__dirname, "templates")
const previewLoc = fs.existsSync(templateLoc) ? templateLoc : __dirname
const previewHbs = loadHandlebarsFile(join(previewLoc, "preview.hbs"))
ctx.body = await processString(previewHbs, { ctx.body = await processString(previewHbs, {
clientLibPath: objectStore.clientLibraryUrl(appId!, appInfo.version), clientLibPath: objectStore.clientLibraryUrl(appId!, appInfo.version),
}) })

View File

@ -251,9 +251,19 @@ class LinkController {
// find the docs that need to be deleted // find the docs that need to be deleted
let toDeleteDocs = thisFieldLinkDocs let toDeleteDocs = thisFieldLinkDocs
.filter(doc => { .filter(doc => {
let correctDoc = let correctDoc
doc.doc1.fieldName === fieldName ? doc.doc2 : doc.doc1 if (
return rowField.indexOf(correctDoc.rowId) === -1 doc.doc1.tableId === table._id! &&
doc.doc1.fieldName === fieldName
) {
correctDoc = doc.doc2
} else if (
doc.doc2.tableId === table._id! &&
doc.doc2.fieldName === fieldName
) {
correctDoc = doc.doc1
}
return correctDoc && rowField.indexOf(correctDoc.rowId) === -1
}) })
.map(doc => { .map(doc => {
return { ...doc, _deleted: true } return { ...doc, _deleted: true }