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

false error on @relation in vscode extension when using multiple schemas #1254

Closed tmax22 closed 5 months ago

tmax22 commented 6 months ago

Description and expected behavior

false error values of "references" and "fields" must have the same type, when the type actually the same and zenstack generate creates correct schema. this is an issue with vscode+intelij extensions.

image

// /zmodel/base.zmodel

import "../schema"

abstract model Base {
    id String @id @default(uuid())
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt()

    // require login
    @@deny('all', auth() == null)

    // allow all operations for admin
    @@allow('all', auth().role.name == 'Admin')
}

model User extends Base {
    name String
    email String @unique
    profilePic String
    role Role @relation(fields: [roleId], references: [id])
    roleId String
    serviceResearches Service2Researcher[]

    @@allow('read', true)
}

model Role extends Base {
    name String @unique
    users User[]

    @@allow('read', true)
}
// /schema.zmodel

import "zmodel/base"

model Demo extends Base {
    stages DemoStage[] @relation("stages")
}

model DemoStage extends Base {
    owned_stages Demo? @relation("stages", fields: [demoId], references: [id])
    demoId String?
}

same on base by the way

image

Environment (please complete the following information):

update: this bug is only in vscode, but not in intelij

ymc9 commented 5 months ago

Hi @tmax22 , which version of VSCode extension are you using? I tried both the latest and the prerelease one but couldn't reproduce it.

tmax22 commented 5 months ago

Version: 1.88.1 Commit: e170252f762678dec6ca2cc69aba1570769a5d39 Date: 2024-04-10T17:34:12.840Z Electron: 28.2.8 ElectronBuildId: 27744544 Chromium: 120.0.6099.291 Node.js: 18.18.2 V8: 12.0.267.19-electron.0 OS: Linux x64 5.15.150.1-microsoft-standard-WSL2 snap

tmax22 commented 5 months ago

I'm not sure what happened, but now vscode error has gone, but the same error appears on Webstorm now 🙃

ymc9 commented 5 months ago

I'm not sure what happened, but now vscode error has gone, but the same error appears on Webstorm now 🙃

Are you using the V2 prerelease version of VSCode extension? It might be an issue fixed in the v2 release but there isn't a version for it for webstorm yet.

tmax22 commented 5 months ago

nope. im on the normal stable release vscode extension. I'm not sure what's going on and why this happens only sometimes

ymc9 commented 5 months ago

I'm closing it for now. Please reopen if it happens again.