Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many to many tables loss #14

Open
whygee-dev opened this issue Jan 30, 2025 · 0 comments
Open

Many to many tables loss #14

whygee-dev opened this issue Jan 30, 2025 · 0 comments

Comments

@whygee-dev
Copy link

whygee-dev commented Jan 30, 2025

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant