From f1800007723133ffe7acd659f2945e33d9c27a8d Mon Sep 17 00:00:00 2001 From: Hugo FOYART <11079152+foyarash@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:47:12 +0200 Subject: [PATCH 1/2] fix: crash on undefined relationship length --- .changeset/metal-ties-help.md | 5 +++++ packages/next-admin/src/utils/server.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/metal-ties-help.md diff --git a/.changeset/metal-ties-help.md b/.changeset/metal-ties-help.md new file mode 100644 index 00000000..4e3ba3a6 --- /dev/null +++ b/.changeset/metal-ties-help.md @@ -0,0 +1,5 @@ +--- +"@premieroctet/next-admin": patch +--- + +fix: crash on undefined relationship length (#465) diff --git a/packages/next-admin/src/utils/server.ts b/packages/next-admin/src/utils/server.ts index 513492a7..7acd0019 100644 --- a/packages/next-admin/src/utils/server.ts +++ b/packages/next-admin/src/utils/server.ts @@ -439,8 +439,8 @@ export const findRelationInData = ( * because one side of a one-to-one relation will not have relationFromFields */ if ( - (dmmfPropertyRelationFromFields!.length > 0 && - dmmfPropertyRelationToFields!.length > 0) || + (dmmfPropertyRelationFromFields?.length && + dmmfPropertyRelationToFields?.length) || !dmmfProperty.isList ) { const idProperty = getModelIdProperty(dmmfProperty.type as ModelName); From ba3bd3d184f3f5e888ca0106662d8152dfa7bbce Mon Sep 17 00:00:00 2001 From: Hugo FOYART <11079152+foyarash@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:58:46 +0200 Subject: [PATCH 2/2] add optional operator in fillRelationInSchema --- packages/next-admin/src/utils/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next-admin/src/utils/server.ts b/packages/next-admin/src/utils/server.ts index 7acd0019..a8e3299a 100644 --- a/packages/next-admin/src/utils/server.ts +++ b/packages/next-admin/src/utils/server.ts @@ -252,7 +252,7 @@ export const fillRelationInSchema = if (fieldKind === "object") { const modelNameRelation = fieldType as ModelName; - if (relationToFields!.length > 0) { + if (relationToFields?.length) { //Relation One-to-Many, Many side const enumeration: Enumeration[] = []; schema.definitions[modelName].properties[fieldName] = {