zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

[Feature request] Support implicit inversed relationship #613

Closed jiashengguo closed 7 months ago

jiashengguo commented 1 year ago

Support the below schema:

model User {
  id    Int    @id @default(autoincrement())
 // posts Post[].    no need to specify it in Zmodel,  ZenStack will generate it in the schema.prisma file.
}

model Post {
  id       Int  @id @default(autoincrement())
  author   User @relation(fields: [authorId], references: [id])
  authorId Int
}

Need naming convention rule to generate the inversed relation. Also, need a way to distinguish between one-to-one and one-to-many.

Take a reference of how EF handles it: https://learn.microsoft.com/en-us/ef/core/modeling/relationships/one-to-one#one-to-one-without-navigation-to-dependent

jmarbutt commented 1 year ago

This would dramatically improve cases like this where it large schemas reference a common table like User

ymc9 commented 7 months ago

Closing as it's covered by #430