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
27 lines
985 B
Plaintext
27 lines
985 B
Plaintext
import { valueIsValueWithRelation } from 'payload/shared';
|
|
export const transformRelationship = ({ baseRow, data, field, relationships })=>{
|
|
const relations = Array.isArray(data) ? data : [
|
|
data
|
|
];
|
|
relations.forEach((relation, i)=>{
|
|
if (relation) {
|
|
const relationRow = {
|
|
...baseRow
|
|
};
|
|
if ('hasMany' in field && field.hasMany) {
|
|
relationRow.order = i + 1;
|
|
}
|
|
if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) {
|
|
relationRow[`${relation.relationTo}ID`] = relation.value;
|
|
relationships.push(relationRow);
|
|
} else if (typeof field.relationTo === 'string') {
|
|
relationRow[`${field.relationTo}ID`] = relation;
|
|
if (relation) {
|
|
relationships.push(relationRow);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
};
|
|
|
|
//# sourceMappingURL=relationships.js.map |