Merge branch 'master' of github.com:Budibase/budibase into bug/relationship-display-id

This commit is contained in:
mike12345567 2021-02-25 12:36:16 +00:00
commit cd36739c23
3 changed files with 34 additions and 1 deletions

View File

@ -29,6 +29,12 @@
// Prevent modal closing if there were errors // Prevent modal closing if there were errors
return false return false
} }
if (rowResponse.status === 500) {
notifier.danger(rowResponse.message)
return false
}
notifier.success("Row saved successfully.") notifier.success("Row saved successfully.")
backendUiStore.actions.rows.save(rowResponse) backendUiStore.actions.rows.save(rowResponse)
} }

View File

@ -12,6 +12,11 @@ exports.FieldTypes = {
AUTO: "auto", AUTO: "auto",
} }
exports.RelationshipTypes = {
ONE_TO_MANY: "one-to-many",
MANY_TO_MANY: "many-to-many",
}
exports.AuthTypes = { exports.AuthTypes = {
APP: "app", APP: "app",
BUILDER: "builder", BUILDER: "builder",

View File

@ -2,7 +2,7 @@ const CouchDB = require("../index")
const { IncludeDocs, getLinkDocuments } = require("./linkUtils") const { IncludeDocs, getLinkDocuments } = require("./linkUtils")
const { generateLinkID } = require("../utils") const { generateLinkID } = require("../utils")
const Sentry = require("@sentry/node") const Sentry = require("@sentry/node")
const { FieldTypes } = require("../../constants") const { FieldTypes, RelationshipTypes } = require("../../constants")
const { isEqual } = require("lodash") const { isEqual } = require("lodash")
/** /**
@ -163,8 +163,30 @@ class LinkController {
? linkDoc.doc2.rowId ? linkDoc.doc2.rowId
: linkDoc.doc1.rowId : linkDoc.doc1.rowId
}) })
// if 1:N, ensure that this ID is not already attached to another record
const linkedTable = await this._db.get(field.tableId)
const linkedSchema = linkedTable.schema[field.fieldName]
// iterate through the link IDs in the row field, see if any don't exist already // iterate through the link IDs in the row field, see if any don't exist already
for (let linkId of rowField) { for (let linkId of rowField) {
if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) {
const links = await getLinkDocuments({
appId: this._appId,
tableId: field.tableId,
rowId: linkId,
includeDocs: IncludeDocs.INCLUDE,
})
// The 1 side of 1:N is already related to something else
// You must remove the existing relationship
if (links.length > 0) {
throw new Error(
`1:N Relationship Error: Record already linked to another.`
)
}
}
if (linkId && linkId !== "" && linkDocIds.indexOf(linkId) === -1) { if (linkId && linkId !== "" && linkDocIds.indexOf(linkId) === -1) {
// first check the doc we're linking to exists // first check the doc we're linking to exists
try { try {