Handling empty relationship column the same way other columns are handled, it won't do anything until it is valid - but doesn't error.

This commit is contained in:
mike12345567 2020-10-12 17:02:52 +01:00
parent 352ff82885
commit 1dea4f24b7
2 changed files with 20 additions and 7 deletions

View File

@ -234,8 +234,16 @@ class LinkController {
for (let fieldName of Object.keys(schema)) {
const field = schema[fieldName]
if (field.type === "link") {
// handle this in a separate try catch, want
// the put to bubble up as an error, if can't update
// table for some reason
let linkedModel
try {
linkedModel = await this._db.get(field.modelId)
} catch (err) {
continue
}
// create the link field in the other model
const linkedModel = await this._db.get(field.modelId)
linkedModel.schema[field.fieldName] = {
name: field.fieldName,
type: "link",

View File

@ -42,6 +42,7 @@ exports.updateLinks = async function({
model,
oldModel,
}) {
const baseReturnObj = record == null ? model : record
if (instanceId == null) {
throw "Cannot operate without an instance ID."
}
@ -50,12 +51,16 @@ exports.updateLinks = async function({
arguments[0].modelId = model._id
}
let linkController = new LinkController(arguments[0])
if (
!(await linkController.doesModelHaveLinkedFields()) &&
(oldModel == null ||
!(await linkController.doesModelHaveLinkedFields(oldModel)))
) {
return record
try {
if (
!(await linkController.doesModelHaveLinkedFields()) &&
(oldModel == null ||
!(await linkController.doesModelHaveLinkedFields(oldModel)))
) {
return baseReturnObj
}
} catch (err) {
return baseReturnObj
}
switch (eventType) {
case EventType.RECORD_SAVE: