{"record":{"id":"1306cc3caf470398","repo":"Budibase/budibase","slug":"unable-to-lookup-relationships-undefined-column","errorCode":null,"errorMessage":"Unable to lookup relationships - undefined column properties.","messagePattern":"Unable to lookup relationships - undefined column properties\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/api/controllers/row/ExternalRequest.ts","lineNumber":454,"sourceCode":"        !field.fieldName ||\n        isOneSide(field)\n      ) {\n        continue\n      }\n      let relatedTableId: string | undefined,\n        lookupField: string | undefined,\n        fieldName: string | undefined\n      if (isManyToMany(field)) {\n        relatedTableId = field.through\n        lookupField = primaryKey\n        fieldName = field.throughTo || primaryKey\n      } else if (isManyToOne(field)) {\n        relatedTableId = field.tableId\n        lookupField = field.foreignKey\n        fieldName = field.fieldName\n      }\n      if (!relatedTableId || !lookupField || !fieldName) {\n        throw new Error(\n          \"Unable to lookup relationships - undefined column properties.\"\n        )\n      }\n\n      if (!lookupField || !row?.[lookupField]) {\n        continue\n      }\n      const endpoint = getEndpoint(relatedTableId, Operation.READ)\n      const relatedTable = this.tables[endpoint.entityId]\n      if (!relatedTable) {\n        throw new Error(\"unable to find related table\")\n      }\n      const response = await makeExternalQuery({\n        endpoint,\n        filters: {\n          equal: {\n            [fieldName]: row[lookupField],\n          },","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/row/ExternalRequest.ts#L436-L472","documentation":"lookupRelations resolves a relationship column into (relatedTableId, lookupField, fieldName) by inspecting the column's type. For many-to-one it uses field.tableId/field.foreignKey; for other relationship types the analogous properties. If after the branch any of these is falsy, the relationship column is malformed or an unsupported shape, so it throws rather than producing a broken query.","triggerScenarios":"Calling related() on a row where the relationship column in the external table definition lacks tableId/foreignKey/fieldName — e.g. schema out of sync, a relationship column defined without a foreign key, or a column misdetected as a relationship type.","commonSituations":"Datasource schema not re-fetched after the underlying DB schema changed; manually edited datasource config missing `foreignKey`; datasource connector returning partial column metadata; mismatched relationship direction detection (isManyToOne/isOneToMany both false).","solutions":["Re-fetch/sync the datasource schema so relationship columns carry tableId, foreignKey and fieldName","Fix the relationship column definition to set the correct foreignKey/tableId","Verify the column is a supported relationship type (one-to-many, many-to-many, many-to-one)"],"exampleFix":"// before\n// column defined without foreign key\n{ name: \"customerContacts\", type: \"link\", tableId: \"customers\" }\n// after\n{ name: \"customerContacts\", type: \"link\", tableId: \"customers\", foreignKey: \"customerId\", fieldName: \"customerId\" }","handlingStrategy":"validation","validationCode":"const col = table.schema[fieldName]\nconst isValidLink = col && (col.type === \"link\" || col.type === \"json\") &&\n  (isManyToOne(col) ? !!(col.tableId && col.foreignKey) : !!(col.tableId && col.fieldName))\nif (!isValidLink) throw new Error(`${fieldName} is not a fully-defined relationship`)","typeGuard":"const isCompleteLink = (col: unknown): col is { tableId: string; foreignKey: string; fieldName: string } =>\n  typeof col === \"object\" && col !== null &&\n  \"tableId\" in col && \"foreignKey\" in col && \"fieldName\" in col","tryCatchPattern":null,"preventionTips":["Run datasource sync after external schema changes","Define every link column with tableId and foreignKey/fieldName","Only treat columns as relationships when the connector reports a supported relationship type"],"tags":["server","external-datasource","relationships","schema"],"backgroundTag":"undefined-relationship-column","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}