-
Notifications
You must be signed in to change notification settings - Fork 34
Description
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.