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({
|
||||
name: "Test 2",
|
||||
description: "og desc",
|
||||
link: [firstRow._id],
|
||||
link: [{_id: firstRow._id}],
|
||||
tableId: table._id,
|
||||
})).body
|
||||
const enriched = await outputProcessing(appId, table, [secondRow])
|
||||
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) {
|
||||
continue
|
||||
}
|
||||
// need to handle an edge case where relationship just wasn't found
|
||||
const value = linkedRow[linkedTable.primaryDisplay] || linkedRow._id
|
||||
if (value) {
|
||||
row[link.fieldName].push(value)
|
||||
const obj = { _id: linkedRow._id }
|
||||
// if we know the display column, add it
|
||||
if (linkedRow[linkedTable.primaryDisplay] != null) {
|
||||
obj.primaryDisplay = linkedRow[linkedTable.primaryDisplay]
|
||||
}
|
||||
row[link.fieldName].push(obj)
|
||||
}
|
||||
}
|
||||
return rows
|
||||
|
|
|
@ -15,6 +15,9 @@ const TYPE_TRANSFORM_MAP = {
|
|||
[null]: [],
|
||||
[undefined]: undefined,
|
||||
parse: link => {
|
||||
if (Array.isArray(link) && typeof link[0] === "object") {
|
||||
return link.map(el => (el && el._id ? el._id : el))
|
||||
}
|
||||
if (typeof link === "string") {
|
||||
return [link]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue