All quizzesMedium
Relations & Migrations
Preview — 3 of 10 questions
How do you define a one-to-many relation between User and Post in Prisma schema?
AAdd @relation on both sides without fields or references
BUse @@relation("UserPosts") attribute on the User model only
COn Post, add a userId foreign key field and author User @relation(fields: [userId], references: [id]); on User, add posts Post[]
DDefine hasMany: Post on User and belongsTo: User on Post
What is the difference between an implicit and explicit many-to-many relation in Prisma?
AImplicit relations require PostgreSQL; explicit work with all databases
BImplicit is faster; explicit adds network overhead
CImplicit many-to-many uses a third join table managed by Prisma; explicit many-to-many uses a custom join model with additional fields
DExplicit many-to-many is only needed when more than 3 models are involved
When should you use include vs select in a Prisma query?
Ainclude and select are identical; use whichever is more readable
Binclude adds related models to the result while returning all scalar fields of the main model; select specifies exactly which fields to return (scalars and/or relations), giving you full control and reducing over-fetching
Cselect is only available for findMany; include works with all query methods
Dinclude performs a JOIN; select performs a subquery
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.