Skip to content

References are incorrectly resolved to outer scope when used inside collection predicate expression #925

Closed
@ymc9

Description

@ymc9

Case 1:

model User {
    id Int @id @default(autoincrement())
    company Company[]
    test Int
  
    // "this.test" should trigger an error, but it's incorrectly resolved to `User.test`
    @@allow('read', auth().company?[staff?[companyId == this.test]])
}
  
model Company {
    id Int @id @default(autoincrement())
    user User @relation(fields: [userId], references: [id])
    userId Int
  
    staff Staff[]
    @@allow('read', true)
}
  
model Staff {
    id Int @id @default(autoincrement())
  
    company Company @relation(fields: [companyId], references: [id])
    companyId Int
  
    @@allow('read', true)
  }

Case 2:

model User {
    id Int @id @default(autoincrement())
    company Company[]
    test Int
  
    // "test" should trigger an error, but it's incorrectly resolved to `User.test`
    @@allow('read', auth().company?[staff?[companyId == test]])
}
  
model Company {
    id Int @id @default(autoincrement())
    user User @relation(fields: [userId], references: [id])
    userId Int
  
    staff Staff[]
    @@allow('read', true)
}
  
model Staff {
    id Int @id @default(autoincrement())
  
    company Company @relation(fields: [companyId], references: [id])
    companyId Int
  
    @@allow('read', true)
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions