Closed
Description
Description and expected behavior
The upsert operation on multiple nested relations is applied only to the last relation. Works fine with pure PrismaClient.
Environment (please complete the following information):
- ZenStack version: 1.10.0
- Prisma version: 5.10.2
- Database type: postgres
Additional context
Data model:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Project {
id String @id @unique @default(uuid())
Fields Field[]
@@allow('all', true)
}
model Field {
id String @id @unique @default(uuid())
name String
Project Project @relation(fields: [projectId], references: [id])
projectId String
@@allow('all', true)
}
Code:
const project = await prisma.project.create({
include: { Fields: true },
data: {
Fields: {
create: [
{ name: 'first' },
{ name: 'second' },
]
}
},
});
console.log(project);
const updated = await prisma.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: [
{
where: { id: project.Fields[0].id },
create: { name: 'firstXXX' },
update: { name: 'firstXXX' }
},
{
where: { id: project.Fields[1].id },
create: { name: 'secondXXX' },
update: { name: 'secondXXX' }
}
]
}
}
})
console.log(updated);
When using pure PrismaClient this is the result
{
id: '1',
Fields: [
{
id: 'd8aaa0f1-3f6a-4f21-ae7d-71b9685b4598',
name: 'first', <-------------------------------------------------------------- ORIGINAL NAME
projectId: '1'
},
{
id: 'bb2e15b3-35b1-443e-8db5-e412c10fca94',
name: 'second', <------------------------------------------------------------- ORIGINAL NAME
projectId: '1'
}
]
}
{
id: '1',
Fields: [
{
id: 'd8aaa0f1-3f6a-4f21-ae7d-71b9685b4598',
name: 'firstXXX', <----------------------------------------------------------- UPDATED NAME
projectId: '1'
},
{
id: 'bb2e15b3-35b1-443e-8db5-e412c10fca94',
name: 'secondXXX', <---------------------------------------------------------- UPDATED NAME
projectId: '1'
}
]
}
but with enhanced prisma client, this is the result
{
id: '1',
Fields: [
{
id: 'b12b4216-c190-404d-844b-47d31d7917e7',
name: 'first', <-------------------------------------------------------------- ORIGINAL NAME
projectId: '1'
},
{
id: '004fe98e-c1e3-4c28-bf6b-fc76463c5257',
name: 'second', <------------------------------------------------------------- ORIGINAL NAME
projectId: '1'
}
]
}
{
id: '1',
Fields: [
{
id: 'b12b4216-c190-404d-844b-47d31d7917e7',
name: 'first', <-------------------------------------------------------------- !!! STILL ORIGINAL NAME
projectId: '1'
},
{
id: '004fe98e-c1e3-4c28-bf6b-fc76463c5257',
name: 'secondXXX', <---------------------------------------------------------- UPDATED NAME
projectId: '1'
}
]
}