Fix relation matching

This commit is contained in:
Vencislav Atanasov 2024-09-23 18:55:05 +03:00
parent 4128e0e68a
commit c3d38a0fae
1 changed files with 3 additions and 2 deletions

View File

@ -49,11 +49,12 @@ export const normalizeResponse = (items = [], relations = []) =>
...item, ...item,
...Object.fromEntries(relations.map(([field, collection, idField]) => { ...Object.fromEntries(relations.map(([field, collection, idField]) => {
const key = item[idField]; const key = item[idField];
const fn = Array.isArray(key) ? 'filter' : 'find';
return [ return [
field, field,
collection[fn](item => item.id === key), Array.isArray(key) ?
collection.filter(item => key.includes(item.id)) :
collection.find(item => item.id === key),
]; ];
})), })),
}) })