If you use an implicit many-to-many relation instead of an explicit one, it makes the Prisma Client API simpler (because, for example, you have one fewer level of nesting inside of nested writes). However, Prisma manages this relation table. The implicit many-to-many relation still manifests in a relation table in the underlying database. You cannot use a in place of an use either of these features, you must set up an explicit many-to-many instead.Implicit many-to-many relations require both models to have a single Be aware of the following: implicit many-to-many relations, where Prisma manages the relation table and it does not appear in the Prisma schema.explicit many-to-many relations, where the relation table is represented as an explicit model in your Prisma schema. Many-to-many relations in relational databases can be modelled in two ways: Implicit and explicit many-to-many relations See the MongoDB section for more details. Notice that the syntax is slightly different between relational databases and MongoDB - particularly for many-to-many relations.įor relational databases, the following entity relationship diagram represents the database that corresponds to the sample Prisma schema:įor MongoDB, Prisma uses a normalized data model design, which means that documents reference each other by ID in a similar way to relational databases. These relations do not require the attribute unless you need to disambiguate relations. This example uses implicit many-to-many relations. In the Prisma schema, the foreign key / primary key relationship is represented by the attribute on the author field: The authorId column in the Post table references the id column in the User table. A primary key column in the User table named id.A foreign key column in the Post table named authorId.Foreign keys are stored on one side of the relation. In SQL, you use a foreign key to create a relation between two tables. The following entity relationship diagram defines the same one-to-many relation between the User and Post tables in a relational database: Relations in the database Relational databases This field does exist in the database - it is the foreign key that connects Post and User.Īt a Prisma level, a connection between two models is always represented by a relation field on each side of the relation. The scalar authorId field, which is referenced by the attribute.These fields are used to generate the Prisma Client. Relation fields define connections between models at the Prisma level and do not exist in the database. Two relation fields: author and posts.At a Prisma level, the User / Post relation is made up of:
0 Comments
Leave a Reply. |