Skip to content

Field access policy with relation field access cause compile error  #703

Closed
@jiashengguo

Description

@jiashengguo
model User {
    id Int @id @default(autoincrement())
    name String?
    admin Boolean @default(false)

    companiesWorkedFor Company[]

    username String @unique @allow("all", auth() == this) @allow('read', companiesWorkedFor?[owner == auth()]) @allow("all", auth().admin)
}

model Company {
    id Int @id @default(autoincrement())
    name String?
    owner User @relation(fields: [ownerId], references: [id])
    ownerId Int
}

After running zenstack generate, it will shows the below error:

node_modules/.zenstack/policy.ts:15:90 - error TS1005: ':' expected.

15                     input, ['id']) || (input?.companiesWorkedFor ? (input?.owner == user)) || (user?.admin ?? null))

It misses the : null in the collection ex

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions