Files
klz-cables.com/.pnpm-store/v10/files/a7/1a249b29ada5efb95019a4123d0ecf63544f090e440e26d6df219169765629c063f27227fba285a3a758130fc3d8cc8d5e10eeeacb2feca2a83bc56c86330e
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

69 lines
2.5 KiB
Plaintext

export const transformRelationship = ({ field, locale, ref, relations, withinArrayOrBlockLocale })=>{
let result;
if (!('hasMany' in field) || field.hasMany === false) {
let relation = relations[0];
if (withinArrayOrBlockLocale) {
relation = relations.find((rel)=>rel.locale === withinArrayOrBlockLocale);
}
if (relation) {
// Handle hasOne Poly
if (Array.isArray(field.relationTo)) {
const matchedRelation = Object.entries(relation).find(([key, val])=>{
return val !== null && ![
'id',
'locale',
'order',
'parent',
'path'
].includes(key);
});
if (matchedRelation) {
const relationTo = matchedRelation[0].replace('ID', '');
result = {
relationTo,
value: matchedRelation[1]
};
}
}
}
} else {
const transformedRelations = [];
relations.forEach((relation)=>{
let matchedLocale = true;
if (withinArrayOrBlockLocale) {
matchedLocale = relation.locale === withinArrayOrBlockLocale;
}
// Handle hasMany
if (!Array.isArray(field.relationTo)) {
const relatedData = relation[`${field.relationTo}ID`];
if (relatedData && matchedLocale) {
transformedRelations.push(relatedData);
}
} else {
// Handle hasMany Poly
const matchedRelation = Object.entries(relation).find(([key, val])=>val !== null && ![
'id',
'locale',
'order',
'parent',
'path'
].includes(key) && matchedLocale);
if (matchedRelation) {
const relationTo = matchedRelation[0].replace('ID', '');
transformedRelations.push({
relationTo,
value: matchedRelation[1]
});
}
}
});
result = transformedRelations;
}
if (locale) {
ref[field.name][locale] = result;
} else {
ref[field.name] = result;
}
};
//# sourceMappingURL=relationship.js.map