Skip to content

[Bug]: @adminjs/relations - OneToMany issue - NestJS + Prisma #1595

@vogloblinsky

Description

@vogloblinsky

Contact Details

No response

What happened?

I am trying to reproduce the example of the documentation : https://docs.adminjs.co/basics/features/relations

I have this prisma model :

generator client {
    provider = "prisma-client-js"
}

datasource db {
    provider = "postgresql"
    url      = env("DATABASE_URL")
}

model Organization {
    id      Int      @id @default(autoincrement())
    name    String
    persons Person[]
}

model Person {
    id             Int          @id @default(autoincrement())
    name           String
    email          String
    organization   Organization @relation(fields: [organizationId], references: [id])
    organizationId Int
}

and these two definitions for AdminJS :

export const createPersonResource = () => ({
  resource: {
    model: getModelByName('Person'),
    client: prisma,
  },
  features: [targetRelationSettingsFeature()],
});
export const createOrganizationResource = () => ({
  resource: {
    model: getModelByName('Organization'),
    client: prisma,
  },
  features: [
    owningRelationSettingsFeature({
      componentLoader,
      licenseKey: process.env.ADMINJS_LICENSE_KEY,
      relations: {
        persons: {
          type: RelationType.OneToMany,
          target: {
            joinKey: 'organizationId',
            resourceId: 'Person',
          },
        },
      },
    }),
  ],
});

When i open a detail page of an Organization, i have this error in the terminal (log output below)

Bug prevalence

Everytime

AdminJS dependencies version

"@adminjs/express": "^6.1.0",
"@adminjs/nestjs": "^6.1.0",
"@adminjs/prisma": "^5.0.1",
"@adminjs/relations": "^1.0.0",
"@nestjs/common": "^10.3.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.3.0",
"@nestjs/platform-express": "^10.3.0",
"@prisma/client": "^5.7.1",
"adminjs": "^7.5.2",
"express-formidable": "^1.2.0",
"express-session": "^1.17.3",
"pg": "latest",
"reflect-metadata": "^0.2.1",
"rxjs": "^7.8.1"

What browsers do you see the problem on?

image

Relevant log output

[Nest] 8336  - 20/12/2023 16:41:21   ERROR [ExceptionsHandler] Cannot read properties of null (reading 'type')
TypeError: Cannot read properties of null (reading 'type')
    at file:///Users/vincent/Documents/www/Orange/marathon-pour-tous/adminjs-debug-relations-nestjs-prisma/node_modules/@adminjs/prisma/src/utils/converters.ts:40:59
    at Array.reduce (<anonymous>)
    at convertFilter (file:///Users/vincent/Documents/www/Orange/marathon-pour-tous/adminjs-debug-relations-nestjs-prisma/node_modules/@adminjs/prisma/src/utils/converters.ts:39:31)
    at Resource.find (file:///Users/vincent/Documents/www/Orange/marathon-pour-tous/adminjs-debug-relations-nestjs-prisma/node_modules/@adminjs/prisma/src/Resource.ts:70:13)
    at oneToManyHandler (file:///Users/vincent/Documents/www/Orange/marathon-pour-tous/adminjs-debug-relations-nestjs-prisma/node_modules/@adminjs/relations/lib/actions/one-to-many/one-to-many.handler.js:1:623)
    at file:///Users/vincent/Documents/www/Orange/marathon-pour-tous/adminjs-debug-relations-nestjs-prisma/node_modules/@adminjs/relations/lib/actions/relations.handler.js:1:727
    at file:///Users/vincent/Documents/www/Orange/marathon-pour-tous/adminjs-debug-relations-nestjs-prisma/node_modules/adminjs/lib/backend/decorators/action/action-decorator.js:98:90

Relevant code that's giving you issues

In the convertFilter function, if i log the filters i got this :

{
  organizationId: { path: 'organizationId', property: null, value: '2' }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions