Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two one-to-many relations on the same model generated wrong model meta data #1241

Closed
jiashengguo opened this issue Apr 11, 2024 · 0 comments
Closed
Labels
Milestone

Comments

@jiashengguo
Copy link
Member

jiashengguo commented Apr 11, 2024

Running zenstack generate for below model files

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider   = "postgresql"
  url = env('DATABASE_URL')
}

plugin prisma {
  provider = '@core/prisma'
  output = './prisma/schema.prisma'
}

model User {
  id String @id @default(uuid()) @db.Uuid
  todos Todo[]

  @@auth
  @@allow('all', true)
}

model Todo {
  id String @id @default(uuid()) @db.Uuid

  user_id String @db.Uuid
  user User @relation(fields: [user_id], references: [id])

  images File[] @relation("todo_images")
  documents File[] @relation("todo_documents")

  @@allow('all', true)
}

model File {
  id String @id @default(uuid()) @db.Uuid
  s3_key String @unique
  label String

  todo_image_id String? @db.Uuid
  todo_image Todo? @relation("todo_images", fields: [todo_image_id], references: [id])

  todo_document_id String? @db.Uuid
  todo_document Todo? @relation("todo_documents", fields: [todo_document_id], references: [id])

  @@allow('all', true)
}

The backLink generated model-meta.js is incorrect:

const metadata = {
fields:{
     file:{
              ...
             todo_document: {
                name: "todo_document",
                type: "Todo",
                isDataModel: true,
                isOptional: true,
                attributes: [{ "name": "@relation", "args": [{ "value": "todo_documents" }] }],
                backLink: 'images',  // here should be **documents**
                isRelationOwner: true,
                foreignKeyMapping: { "id": "todo_document_id" },
            },
            ...
         }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants