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:
parent
5ac30510c6
commit
b86640772b
|
@ -24,7 +24,7 @@ import AWS from "aws-sdk"
|
|||
import fs from "fs"
|
||||
import sdk from "../../../sdk"
|
||||
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")
|
||||
|
||||
|
@ -212,7 +212,9 @@ export const serveBuilderPreview = async function (ctx: Ctx) {
|
|||
|
||||
if (!env.isJest()) {
|
||||
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, {
|
||||
clientLibPath: objectStore.clientLibraryUrl(appId!, appInfo.version),
|
||||
})
|
||||
|
|
|
@ -251,9 +251,19 @@ class LinkController {
|
|||
// find the docs that need to be deleted
|
||||
let toDeleteDocs = thisFieldLinkDocs
|
||||
.filter(doc => {
|
||||
let correctDoc =
|
||||
doc.doc1.fieldName === fieldName ? doc.doc2 : doc.doc1
|
||||
return rowField.indexOf(correctDoc.rowId) === -1
|
||||
let correctDoc
|
||||
if (
|
||||
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 => {
|
||||
return { ...doc, _deleted: true }
|
||||
|
|
Loading…
Reference in New Issue