Having the server send out _id and primaryDisplay in an object for relationships, also accepting objects and coercing them on way in.
This commit is contained in:
parent
c8a28ac927
commit
91878ed2ce
|
@ -282,12 +282,13 @@ describe("/rows", () => {
|
||||||
const secondRow = (await createRow({
|
const secondRow = (await createRow({
|
||||||
name: "Test 2",
|
name: "Test 2",
|
||||||
description: "og desc",
|
description: "og desc",
|
||||||
link: [firstRow._id],
|
link: [{_id: firstRow._id}],
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
})).body
|
})).body
|
||||||
const enriched = await outputProcessing(appId, table, [secondRow])
|
const enriched = await outputProcessing(appId, table, [secondRow])
|
||||||
expect(enriched[0].link.length).toBe(1)
|
expect(enriched[0].link.length).toBe(1)
|
||||||
expect(enriched[0].link[0]).toBe("Test Contact")
|
expect(enriched[0].link[0]._id).toBe(firstRow._id)
|
||||||
|
expect(enriched[0].link[0].primaryDisplay).toBe("Test Contact")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -175,11 +175,12 @@ exports.attachLinkedPrimaryDisplay = async (appId, table, rows) => {
|
||||||
if (!linkedRow || !linkedTable) {
|
if (!linkedRow || !linkedTable) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// need to handle an edge case where relationship just wasn't found
|
const obj = { _id: linkedRow._id }
|
||||||
const value = linkedRow[linkedTable.primaryDisplay] || linkedRow._id
|
// if we know the display column, add it
|
||||||
if (value) {
|
if (linkedRow[linkedTable.primaryDisplay] != null) {
|
||||||
row[link.fieldName].push(value)
|
obj.primaryDisplay = linkedRow[linkedTable.primaryDisplay]
|
||||||
}
|
}
|
||||||
|
row[link.fieldName].push(obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rows
|
return rows
|
||||||
|
|
|
@ -15,6 +15,9 @@ const TYPE_TRANSFORM_MAP = {
|
||||||
[null]: [],
|
[null]: [],
|
||||||
[undefined]: undefined,
|
[undefined]: undefined,
|
||||||
parse: link => {
|
parse: link => {
|
||||||
|
if (Array.isArray(link) && typeof link[0] === "object") {
|
||||||
|
return link.map(el => (el && el._id ? el._id : el))
|
||||||
|
}
|
||||||
if (typeof link === "string") {
|
if (typeof link === "string") {
|
||||||
return [link]
|
return [link]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue