Query works but getting a TS error

Hello! I wrote a query that is working but I am getting a Typescript error that I cannot debug. Could someone more experienced tell me what this could be about? Of course I don't want you to work for me. Not looking for help solving the problem, just some steering on the right direction. Thank you so much in advance. Query:
await database.play.create({
data: {
date: new Date(gameSchema.datePlayed),
location: gameSchema.location,
duration: gameSchema.durationMinutes,
notes: gameSchema.extra,
userId: user.id,
game: {
connect: { id: gameSchema.gameId }, // Assuming gameId corresponds to the Game model's id
},
players: {
create: [
...gameSchema.players.map((player) => ({
player: {
connectOrCreate: {
where: {
OwnerIdBggUsername: {
ownerId: user.id,
bggUsername: player.bggUsername,
},
},
create: {
name: player.name,
bggUsername: player.bggUsername,
ownerId: user.id,
},
},
},
team: player.team,
score: player.score,
winner: player.won,
firstTime: player.firstTime,
})),
],
},
},
});
await database.play.create({
data: {
date: new Date(gameSchema.datePlayed),
location: gameSchema.location,
duration: gameSchema.durationMinutes,
notes: gameSchema.extra,
userId: user.id,
game: {
connect: { id: gameSchema.gameId }, // Assuming gameId corresponds to the Game model's id
},
players: {
create: [
...gameSchema.players.map((player) => ({
player: {
connectOrCreate: {
where: {
OwnerIdBggUsername: {
ownerId: user.id,
bggUsername: player.bggUsername,
},
},
create: {
name: player.name,
bggUsername: player.bggUsername,
ownerId: user.id,
},
},
},
team: player.team,
score: player.score,
winner: player.won,
firstTime: player.firstTime,
})),
],
},
},
});
5 Replies
Prisma AI Help
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
AmazingViegas
AmazingViegasOP5d ago
The schema related to this is:
model Play {
id Int @id @default(autoincrement())
gameId Int
duration Int?
location String?
userId String
date DateTime
notes String?
game Game @relation(fields: [gameId], references: [id])
players PlayPlayer[]
}

model PlayPlayer {
id Int @id @default(autoincrement())
play Play @relation(fields: [playId], references: [id])
playId Int
player Player @relation(fields: [playerId], references: [id])
playerId Int
team String?
score Int?
winner Boolean
firstTime Boolean
}

model Player {
id Int @id @default(autoincrement())
name String
bggUsername String?
bggId String?
playPlayers PlayPlayer[]
ownerId String

@@unique(name: "OwnerIdName", [ownerId, name])
@@unique(name: "OwnerIdBggId", [ownerId, bggId])
@@unique(name: "OwnerIdBggUsername", [ownerId, bggUsername])
model Play {
id Int @id @default(autoincrement())
gameId Int
duration Int?
location String?
userId String
date DateTime
notes String?
game Game @relation(fields: [gameId], references: [id])
players PlayPlayer[]
}

model PlayPlayer {
id Int @id @default(autoincrement())
play Play @relation(fields: [playId], references: [id])
playId Int
player Player @relation(fields: [playerId], references: [id])
playerId Int
team String?
score Int?
winner Boolean
firstTime Boolean
}

model Player {
id Int @id @default(autoincrement())
name String
bggUsername String?
bggId String?
playPlayers PlayPlayer[]
ownerId String

@@unique(name: "OwnerIdName", [ownerId, name])
@@unique(name: "OwnerIdBggId", [ownerId, bggId])
@@unique(name: "OwnerIdBggUsername", [ownerId, bggUsername])
And this is the error message:
Type '{ player: { connectOrCreate: { where: { OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }; create: { name: string | undefined; bggUsername: string | undefined; ownerId: string; }; }; }; team: string | undefined; score: number; winner: boolean; firstTime: boolean; }[]' is not assignable to type '(Without<PlayPlayerCreateWithoutPlayInput, PlayPlayerUncheckedCreateWithoutPlayInput> & PlayPlayerUncheckedCreateWithoutPlayInput) | (Without<...> & PlayPlayerCreateWithoutPlayInput) | PlayPlayerCreateWithoutPlayInput[] | PlayPlayerUncheckedCreateWithoutPlayInput[] | undefined'.
Type '{ player: { connectOrCreate: { where: { OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }; create: { name: string | undefined; bggUsername: string | undefined; ownerId: string; }; }; }; team: string | undefined; score: number; winner: boolean; firstTime: boolean; }[]' is not assignable to type 'PlayPlayerCreateWithoutPlayInput[]'.
Type '{ player: { connectOrCreate: { where: { OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }; create: { name: string | undefined; bggUsername: string | undefined; ownerId: string; }; }; }; team: string | undefined; score: number; winner: boolean; firstTime: boolean; }[]' is not assignable to type '(Without<PlayPlayerCreateWithoutPlayInput, PlayPlayerUncheckedCreateWithoutPlayInput> & PlayPlayerUncheckedCreateWithoutPlayInput) | (Without<...> & PlayPlayerCreateWithoutPlayInput) | PlayPlayerCreateWithoutPlayInput[] | PlayPlayerUncheckedCreateWithoutPlayInput[] | undefined'.
Type '{ player: { connectOrCreate: { where: { OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }; create: { name: string | undefined; bggUsername: string | undefined; ownerId: string; }; }; }; team: string | undefined; score: number; winner: boolean; firstTime: boolean; }[]' is not assignable to type 'PlayPlayerCreateWithoutPlayInput[]'.
Type '{ player: { connectOrCreate: { where: { OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }; create: { name: string | undefined; bggUsername: string | undefined; ownerId: string; }; }; }; team: string | undefined; score: number; winner: boolean; firstTime: boolean; }' is not assignable to type 'PlayPlayerCreateWithoutPlayInput'.
The types of 'player.connectOrCreate.where' are incompatible between these types.
Type '{ OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }' is not assignable to type 'PlayerWhereUniqueInput'.
Type '{ OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }' is not assignable to type '{ id: number | PlayerOwnerIdNameCompoundUniqueInput | PlayerOwnerIdBggIdCompoundUniqueInput | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdName: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBggId: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBg...'.
Type '{ OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }' is missing the following properties from type '{ id: number | PlayerOwnerIdNameCompoundUniqueInput | PlayerOwnerIdBggIdCompoundUniqueInput | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdName: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBggId: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBg...': id, OwnerIdName, OwnerIdBggId
Type '{ player: { connectOrCreate: { where: { OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }; create: { name: string | undefined; bggUsername: string | undefined; ownerId: string; }; }; }; team: string | undefined; score: number; winner: boolean; firstTime: boolean; }' is not assignable to type 'PlayPlayerCreateWithoutPlayInput'.
The types of 'player.connectOrCreate.where' are incompatible between these types.
Type '{ OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }' is not assignable to type 'PlayerWhereUniqueInput'.
Type '{ OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }' is not assignable to type '{ id: number | PlayerOwnerIdNameCompoundUniqueInput | PlayerOwnerIdBggIdCompoundUniqueInput | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdName: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBggId: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBg...'.
Type '{ OwnerIdBggUsername: { ownerId: string; bggUsername: string | undefined; }; }' is missing the following properties from type '{ id: number | PlayerOwnerIdNameCompoundUniqueInput | PlayerOwnerIdBggIdCompoundUniqueInput | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdName: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBggId: number | ... 2 more ... | PlayerOwnerIdBggUsernameCompoundUniqueInput; OwnerIdBg...': id, OwnerIdName, OwnerIdBggId
RaphaelEtim
RaphaelEtim5d ago
Hi @AmazingViegas I'm trying to reproduce this issue and noticed the Game schema is missing. What does Game schema look like as it's erroring out in my IDE?
AmazingViegas
AmazingViegasOP5d ago
Sorry, this is the game schema:
model Game {
id Int @id @default(autoincrement())
title String @unique
identifier String @unique
description String?
createdAt DateTime @default(now())
maxPlayers Int?
minPlayers Int?
imageUrl String?
year Int?
chats Chat[]
plays Play[]
favorites FavoriteGame[]
}
model Game {
id Int @id @default(autoincrement())
title String @unique
identifier String @unique
description String?
createdAt DateTime @default(now())
maxPlayers Int?
minPlayers Int?
imageUrl String?
year Int?
chats Chat[]
plays Play[]
favorites FavoriteGame[]
}
RaphaelEtim
RaphaelEtim5d ago
Thank you, I'll take a look at get back to you.

Did you find this page helpful?