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 89 forks source link

[BUG] Nested query does not include polymorphic attributes #1698

Closed Tsimopak closed 2 weeks ago

Tsimopak commented 3 weeks ago

Having the following models:


model House {
  id Int @id @default(autoincrement())
  doorTypeId Int
  door Door @relation(fields: [doorTypeId], references: [id])
  type String
  @@delegate(type)

}

model PrivateHouse extends House {
  card Int

}
model Skyscraper extends House {
  ticket Int

}

model Door {
  id Int @id @default(autoincrement())
  color String
  houses House[]
  type String
  @@delegate(type)

}

model IronDoor extends Door {
  strength Int

}

model WoodenDoor extends Door {
  texture String

}

if I do the following query:

const query = await db.privateHouse.findUnique({
  where: { id: 1 },
  include: {
    door: true
  }
})

The output will be:

query {
  id: 1,
  doorTypeId: 1,
  type: 'PrivateHouse',
  door: { id: 1, color: 'red', type: 'IronDoor' },
  card: 2
}

as you can see it does not include the irondoor attributes, i would suggest to include it, or at least change the syntax of findunique to be the following to include it:

const query = await db.privateHouse.findUnique({
  where: { id: 1 },
  include: {
    door: {
       include: { ironDoor: true }
    }
  }
})

Versions:

  "devDependencies": {
    "prisma": "^5.19.1",
    "typescript": "^5.6.2",
    "zenstack": "2.5.1"
  },
  "dependencies": {
    "@prisma/client": "^5.19.1",
    "@zenstackhq/runtime": "2.5.1"
  }
ymc9 commented 2 weeks ago

Fixed in 2.6.0