From 4d4789c99202ff2366afd75f8b320549ca881e3e Mon Sep 17 00:00:00 2001 From: James Pulec Date: Fri, 6 May 2022 14:43:21 -0700 Subject: [PATCH 1/3] Check for Primary Key Name for UniqueWhereInput --- src/lib/prisma-utils/whereUniqueInput.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/prisma-utils/whereUniqueInput.ts b/src/lib/prisma-utils/whereUniqueInput.ts index 9360177c9..6225fb3b8 100644 --- a/src/lib/prisma-utils/whereUniqueInput.ts +++ b/src/lib/prisma-utils/whereUniqueInput.ts @@ -54,6 +54,9 @@ function getUniqueIdentifierFields(model: DMMF.Model): FieldName[] { // Try finding 2 if (model.primaryKey && model.primaryKey.fields.length > 0) { + if (model.primaryKey.name) { + return [model.primaryKey.name]; + } return model.primaryKey.fields } From 586bc9ced74b06fced12956637c3db3fa2bd90ad Mon Sep 17 00:00:00 2001 From: James Pulec Date: Sun, 6 Nov 2022 22:02:59 -0800 Subject: [PATCH 2/3] chore: fix formatting --- src/lib/prisma-utils/whereUniqueInput.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/prisma-utils/whereUniqueInput.ts b/src/lib/prisma-utils/whereUniqueInput.ts index 6225fb3b8..3337aeb57 100644 --- a/src/lib/prisma-utils/whereUniqueInput.ts +++ b/src/lib/prisma-utils/whereUniqueInput.ts @@ -55,7 +55,7 @@ function getUniqueIdentifierFields(model: DMMF.Model): FieldName[] { // Try finding 2 if (model.primaryKey && model.primaryKey.fields.length > 0) { if (model.primaryKey.name) { - return [model.primaryKey.name]; + return [model.primaryKey.name] } return model.primaryKey.fields } From c407797d7b798875d1e2998bb71553cc4eef4a82 Mon Sep 17 00:00:00 2001 From: James Pulec Date: Sun, 6 Nov 2022 23:18:03 -0800 Subject: [PATCH 3/3] fix: correct logic for create where input --- src/lib/prisma-utils/whereUniqueInput.ts | 8 ++++---- tests/integration/relation1ToN.test.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/prisma-utils/whereUniqueInput.ts b/src/lib/prisma-utils/whereUniqueInput.ts index 3337aeb57..379476062 100644 --- a/src/lib/prisma-utils/whereUniqueInput.ts +++ b/src/lib/prisma-utils/whereUniqueInput.ts @@ -26,8 +26,11 @@ export const createWhereUniqueInput = (source: RecordUnknown, model: DMMF.Model) return pick(source, uniqueIdentifierFields) } + const propertyName = + (model.primaryKey?.fields === uniqueIdentifierFields && model.primaryKey.name) || + TypeScriptOrmCompoundUniquePropertyName(uniqueIdentifierFields) return { - [TypeScriptOrmCompoundUniquePropertyName(uniqueIdentifierFields)]: pick(source, uniqueIdentifierFields), + [propertyName]: pick(source, uniqueIdentifierFields), } } @@ -54,9 +57,6 @@ function getUniqueIdentifierFields(model: DMMF.Model): FieldName[] { // Try finding 2 if (model.primaryKey && model.primaryKey.fields.length > 0) { - if (model.primaryKey.name) { - return [model.primaryKey.name] - } return model.primaryKey.fields } diff --git a/tests/integration/relation1ToN.test.ts b/tests/integration/relation1ToN.test.ts index 2e4e94c95..1fc1a3e17 100644 --- a/tests/integration/relation1ToN.test.ts +++ b/tests/integration/relation1ToN.test.ts @@ -78,7 +78,7 @@ testIntegration({ id1 String id2 String posts Post[] - @@id(fields: [id1, id2]) + @@id(fields: [id1, id2], name: "usersCustomPK") } model Post { id String @id