Fixing an issue whereby in some enrichment calls the count of links would be doubled (counting both sides).
This commit is contained in:
parent
f31cd884ec
commit
e87d9afbaf
|
@ -1,5 +1,5 @@
|
|||
const LinkController = require("./LinkController")
|
||||
const { IncludeDocs, getLinkDocuments, createLinkView } = require("./linkUtils")
|
||||
const { IncludeDocs, getLinkDocuments, createLinkView, getUniqueByProp } = require("./linkUtils")
|
||||
const _ = require("lodash")
|
||||
|
||||
/**
|
||||
|
@ -110,7 +110,12 @@ exports.attachLinkInfo = async (instanceId, rows) => {
|
|||
// now iterate through the rows and all field information
|
||||
for (let row of rows) {
|
||||
// get all links for row, ignore fieldName for now
|
||||
const linkVals = responses.filter(el => el.thisId === row._id)
|
||||
// have to get unique as the previous table query can
|
||||
// return duplicates, could be querying for both tables in a relation
|
||||
const linkVals = getUniqueByProp(
|
||||
responses.filter(el => el.thisId === row._id),
|
||||
"id"
|
||||
)
|
||||
for (let linkVal of linkVals) {
|
||||
// work out which link pertains to this row
|
||||
if (!(row[linkVal.fieldName] instanceof Array)) {
|
||||
|
|
|
@ -92,3 +92,9 @@ exports.getLinkDocuments = async function({
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.getUniqueByProp = (array, prop) => {
|
||||
return array.filter((obj, pos, arr) => {
|
||||
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue