Dependency-dependents relations
I am having difficulty understanding whether my schema is correct, even if it reports no errors. It's basically that I'm trying to express a package registry as part of a package manager, and am having difficulty specifying
dependencies
and dependents
relations as part of the PackageVersion
model.
2 Replies
I give up on Prisma -_-
Hi 👋
I think the confusion stems from having the same relation name
Dependency
for both dependencies and dependents fields. Also, from your code, you are trying to create a self-referencing many-to-many relationship for package dependencies. To properly express this relationship, you need to use distinct names for each side of the relation and add the necessary fields to make it an explicit many-to-many relationship. For example:
Looking at the example i shared, I've introduced a new PackageDependency
model to represent the many-to-many relationship explicitly. The dependencies
field in PackageVersion
now uses the relation name DependencyTo
, representing the versions that this package depends on. The dependents
field in PackageVersion
uses the relation name DependencyFrom
, representing the versions that depend on this package. The PackageDependency
model has two fields referencing PackageVersion
, one for the dependency and one for the dependent.
You may also want to share your full schema in order for us to help you further.