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)) { for (let fieldName of Object.keys(schema)) {
const field = schema[fieldName] const field = schema[fieldName]
if (field.type === "link") { 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 // create the link field in the other model
const linkedModel = await this._db.get(field.modelId)
linkedModel.schema[field.fieldName] = { linkedModel.schema[field.fieldName] = {
name: field.fieldName, name: field.fieldName,
type: "link", type: "link",

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

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

Loading…
Cancel
Save