Merge pull request #7868 from Budibase/bug/sev3/display-column-relationship-bug
Ensure display columns are set when relationships are defined
This commit is contained in:
commit
d1280ba550
|
@ -68,6 +68,7 @@ exports.buildSchemaFromDb = async function (ctx) {
|
||||||
datasource.entities = tables
|
datasource.entities = tables
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDefaultDisplayColumns(datasource)
|
||||||
const dbResp = await db.put(datasource)
|
const dbResp = await db.put(datasource)
|
||||||
datasource._rev = dbResp.rev
|
datasource._rev = dbResp.rev
|
||||||
|
|
||||||
|
@ -78,6 +79,24 @@ exports.buildSchemaFromDb = async function (ctx) {
|
||||||
ctx.body = response
|
ctx.body = response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure all datasource entities have a display name selected
|
||||||
|
*/
|
||||||
|
const setDefaultDisplayColumns = datasource => {
|
||||||
|
//
|
||||||
|
for (let entity of Object.values(datasource.entities)) {
|
||||||
|
if (entity.primaryDisplay) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const notAutoColumn = Object.values(entity.schema).find(
|
||||||
|
schema => !schema.autocolumn
|
||||||
|
)
|
||||||
|
if (notAutoColumn) {
|
||||||
|
entity.primaryDisplay = notAutoColumn.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for variables that have been updated or removed and invalidate them.
|
* Check for variables that have been updated or removed and invalidate them.
|
||||||
*/
|
*/
|
||||||
|
@ -155,6 +174,7 @@ exports.save = async function (ctx) {
|
||||||
const { tables, error } = await buildSchemaHelper(datasource)
|
const { tables, error } = await buildSchemaHelper(datasource)
|
||||||
schemaError = error
|
schemaError = error
|
||||||
datasource.entities = tables
|
datasource.entities = tables
|
||||||
|
setDefaultDisplayColumns(datasource)
|
||||||
}
|
}
|
||||||
|
|
||||||
const dbResp = await db.put(datasource)
|
const dbResp = await db.put(datasource)
|
||||||
|
@ -238,19 +258,6 @@ const buildSchemaHelper = async datasource => {
|
||||||
const connector = new Connector(datasource.config)
|
const connector = new Connector(datasource.config)
|
||||||
await connector.buildSchema(datasource._id, datasource.entities)
|
await connector.buildSchema(datasource._id, datasource.entities)
|
||||||
|
|
||||||
// make sure they all have a display name selected
|
|
||||||
for (let entity of Object.values(datasource.entities ?? {})) {
|
|
||||||
if (entity.primaryDisplay) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const notAutoColumn = Object.values(entity.schema).find(
|
|
||||||
schema => !schema.autocolumn
|
|
||||||
)
|
|
||||||
if (notAutoColumn) {
|
|
||||||
entity.primaryDisplay = notAutoColumn.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const errors = connector.schemaErrors
|
const errors = connector.schemaErrors
|
||||||
let error = null
|
let error = null
|
||||||
if (errors && Object.keys(errors).length > 0) {
|
if (errors && Object.keys(errors).length > 0) {
|
||||||
|
|
Loading…
Reference in New Issue