Fixing an issue that occurs when the table name and the primary display column are the same name.
This commit is contained in:
parent
7d4cd470f2
commit
3f960e4f13
|
@ -121,7 +121,7 @@ export const enrichRows = async (rows, tableId) => {
|
|||
rows.forEach(row => {
|
||||
for (let key of keys) {
|
||||
const type = schema[key].type
|
||||
if (type === "link") {
|
||||
if (type === "link" && Array.isArray(row[key])) {
|
||||
// Enrich row a string join of relationship fields
|
||||
row[`${key}_text`] =
|
||||
row[key]
|
||||
|
|
|
@ -203,19 +203,17 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => {
|
|||
exports.squashLinksToPrimaryDisplay = async (appId, table, enriched) => {
|
||||
const db = new CouchDB(appId)
|
||||
// will populate this as we find them
|
||||
const linkedTables = []
|
||||
for (let [column, schema] of Object.entries(table.schema)) {
|
||||
if (schema.type !== FieldTypes.LINK) {
|
||||
continue
|
||||
}
|
||||
for (let row of enriched) {
|
||||
if (!row[column] || !row[column].length) {
|
||||
const linkedTables = [table]
|
||||
for (let row of enriched) {
|
||||
// this only fetches the table if its not already in array
|
||||
const rowTable = await getLinkedTable(db, row.tableId, linkedTables)
|
||||
for (let [column, schema] of Object.entries(rowTable.schema)) {
|
||||
if (schema.type !== FieldTypes.LINK || !Array.isArray(row[column])) {
|
||||
continue
|
||||
}
|
||||
const newLinks = []
|
||||
for (let link of row[column]) {
|
||||
const linkTblId = link.tableId || getRelatedTableForField(table, column)
|
||||
// this only fetches the table if its not already in array
|
||||
const linkedTable = await getLinkedTable(db, linkTblId, linkedTables)
|
||||
const obj = { _id: link._id }
|
||||
if (link[linkedTable.primaryDisplay]) {
|
||||
|
|
Loading…
Reference in New Issue