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

Implicit many to many relationship always returns all records from other model #1237

Open
thw0rted opened this issue Feb 3, 2025 · 0 comments

Comments

@thw0rted
Copy link

thw0rted commented Feb 3, 2025

I have an implicit many-to-many relationship between two models. Records in model X get associated with records in model Y using connect or create. When I create records of each model using Prismock, then query the result using an include to populate related-record properties, each model-X record comes back with an array containing every record from model-Y.


It might be easier to explain with examples, check out my reproduction and follow the README to see this in action.

In this example, use of a "widget" can be subject to approval. There is a table of approval types -- maybe you need a "license" for it, or "security" has to approve access to it. A relationship captures which widgets need which approval, and also which users are allowed to sign off on a particular type of approval. So, initially a user would not be an approver for any type, then we could make them a "security" approver like prisma.user.update({where: {...}, data: {approverFor: {connect: {name: 'security'}}}).

The bug I think I've found is that if I create a approval types "security" and "license", then create a new user with no approverFor argument, the new user record has an "approverFor" array with both these types. I tried to craft prisma.user.update(...) invocations to remove these "phantom" values but couldn't -- I don't know if entries are actually being made in whatever Prismock uses in-memory as an equivalent of an implicit-relationship table, or if the "include" handler that populates the related records has a bug that makes it ignore the contents of the implicit-table and always return all values from the other table.

UPDATE: I just updated my linked repro to include a new relationship between the Widget and User models, both of which have an autoincrement ID. I previous believed that the issue might be that the model in the "middle" here, ApprovalType, has a String primary key (@id) rather than an auto-increment integer, which I think is unusual. Apparently it happens for auto-ID models too.

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