const generateModels = (
manyToManyFields: DMMF.Field[],
models: DMMF.Model[],
manyToManyTables: DMMF.Model[] = []
): DMMF.Model[] => {
const manyFirst = manyToManyFields.shift();
if (!manyFirst) {
return manyToManyTables;
}
const manySecond = manyToManyFields.find((field) => field.relationName === manyFirst.relationName);
if (!manySecond) {
return manyToManyTables;
}
manyToManyTables.push({
dbName: `_${manyFirst.relationName}`,
name: manyFirst.relationName || '',
primaryKey: null,
uniqueFields: [],
uniqueIndexes: [],
fields: generateJoinFields([manyFirst, manySecond], models),
});
return generateModels(
manyToManyFields.filter((field) => field.relationName !== manyFirst.relationName),
models,
manyToManyTables
);
};
manyToManyFields.shift() mutates the manyToManyFields array and leads to the non-mapping / partial loss of many to many tables in some cases
Are you open to a PR ?
manyToManyFields.shift()mutates the manyToManyFields array and leads to the non-mapping / partial loss of many to many tables in some casesAre you open to a PR ?