Skip to content

Commit

Permalink
fix: crash on undefined relationship length (#467)
Browse files Browse the repository at this point in the history
* fix: crash on undefined relationship length

* add optional operator in fillRelationInSchema
  • Loading branch information
foyarash authored Oct 4, 2024
1 parent 3bfa1a1 commit c25f61c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-ties-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

fix: crash on undefined relationship length (#465)
6 changes: 3 additions & 3 deletions packages/next-admin/src/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c25f61c

Please sign in to comment.