Browse Source

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

gh-pages
mike12345567 6 years ago
parent
commit
1955c73685
  1. 10
      packages/server/src/db/linkedRecords/LinkController.js
  2. 17
      packages/server/src/db/linkedRecords/index.js

10
packages/server/src/db/linkedRecords/LinkController.js

@ -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",

17
packages/server/src/db/linkedRecords/index.js

@ -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:

Loading…
Cancel
Save