Skip to content

input error when querying compound key entry #1435

@fpunny

Description

@fpunny

Description and expected behavior

When trying to run any queries under organization (ie. db.organization.findMany). I would get an input error of Input error. Expected a referenced scalar field of model Member, but found a field of model GoogleIntegration. Code: P2019 Meta: { modelName: 'Organization', details: 'Expected a referenced scalar field of model Member, but found a field of model GoogleIntegration.' }

This seems to only happen when the client is enhanced (ie. .auth { id: "something" }

Schema

/* Interfaces */
abstract model IBase {
    updatedAt DateTime @updatedAt
    createdAt DateTime @default(now())
}

abstract model IAuth extends IBase {
    user   User   @relation(fields: [userId], references: [id], onDelete: Cascade)
    userId String @unique

    @@allow('create', true)
    @@allow('all', auth() == user)
}

abstract model IIntegration extends IBase {
    organization   Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
    organizationId String       @unique

    @@allow('all', organization.members?[user == auth() && type == OWNER])
    @@allow('read', organization.members?[user == auth()])
}

/* Auth Stuff */
model User extends IBase {
    id          String      @id @default(cuid())
    firstName   String
    lastName    String
    google      GoogleAuth?
    memberships Member[]

    @@allow('create', true)
    @@allow('all', auth() == this)
}

model GoogleAuth extends IAuth {
    reference    String @id
    refreshToken String
}

/* Org Stuff */
enum MemberType {
    OWNER
    MEMBER
}

model Organization extends IBase {
    id               String             @id @default(cuid())
    name             String
    members          Member[]
    google           GoogleIntegration?

    @@allow('create', true)
    @@allow('all', members?[user == auth() && type == OWNER])
    @@allow('read', members?[user == auth()])
}


model Member extends IBase {
    type           MemberType   @default(MEMBER)
    organization   Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
    organizationId String
    user           User         @relation(fields: [userId], references: [id], onDelete: Cascade)
    userId         String

    @@id([organizationId, userId])
    @@allow('all', organization.members?[user == auth() && type == OWNER])
    @@allow('read', user == auth())
}

/* Google Stuff */
model GoogleIntegration extends IIntegration {
    reference    String                      @id
}

Environment (please complete the following information):

  • ZenStack version: 2.0.3
  • Prisma version: 5.13.0
  • Database type: Postgresql

Additional context
Not completely sure what is happening, but it seems like it's doing anything but resolve the correct model. Perhaps it has to do with a combination of a composite key + many-to-many relationshop?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions