premieroctet / next-admin

▲ Full-featured admin for Next.js and Prisma
https://next-admin.js.org
MIT License
323 stars 19 forks source link

[BUG] - Advanced Search on related tables not working #481

Closed ZiggyQubert closed 3 weeks ago

ZiggyQubert commented 3 weeks ago

Description

When using the advanced search to search within linked tables the generated prisma object seams to be malformed

Reproduction URL

n/a

Reproduction steps

I have a model flowVersion with a relation flow Flow? @relation("FlowVersion", fields: [flowId], references: [id])

When I add a filter to search by the ID of a flow image image the filtering fails with a prisma error Invalidprisma.flowVersion.findMany()invocation

the applicable part of the query winds up being

{
         flow: {
           equals: "97896ac9-e854-46b4-b27d-d53875d1feee"
         }
       }

and I believe it should be

{
         flow: {
           id: { equals: "97896ac9-e854-46b4-b27d-d53875d1feee" }
         }
       }

Next router

App router

Next Admin version

6.1.6

Screenshots

No response

Next Admin options

No response

Logs

Invalid `prisma.flowVersion.findMany()` invocation:

{
  select: {
    id: true,
    createdAt: true,
    updatedAt: true,
    publishedAt: true,
    createdById: true,
    updatedById: true,
    name: true,
    description: true,
    version: true,
    hidden: true,
    disabled: true,
    thumbnailUri: true,
    workflowDefinition: true,
    inputDefinition: true,
    outputDefinition: true,
    flowId: true,
    parentFlowVersionId: true
  },
  where: {
    AND: [
      {},
      {
        flow: {
          equals: "97896ac9-e854-46b4-b27d-d53875d1feee"
        }
      }
    ]
  },
  orderBy: {
    createdAt: "asc"
  },
  skip: 0,
  take: 10
}

Unknown argument `equals`. Available options are marked with ?.
    at Dn (C:\Users\Ziggy\Desktop\GrabLabs\internal_bp\node_modules\@prisma\client\runtime\library.js:114:8082)
    at Mn.handleRequestError (C:\Users\Ziggy\Desktop\GrabLabs\internal_bp\node_modules\@prisma\client\runtime\library.js:121:7396)
    at Mn.handleAndLogRequestError (C:\Users\Ziggy\Desktop\GrabLabs\internal_bp\node_modules\@prisma\client\runtime\library.js:121:7061)
    at Mn.request (C:\Users\Ziggy\Desktop\GrabLabs\internal_bp\node_modules\@prisma\client\runtime\library.js:121:6745)
    at async l (C:\Users\Ziggy\Desktop\GrabLabs\internal_bp\node_modules\@prisma\client\runtime\library.js:130:9633)
    at async fetchDataList (webpack-internal:///(rsc)/./node_modules/@premieroctet/next-admin/dist/utils/prisma.js:281:16)
    at async getMappedDataList (webpack-internal:///(rsc)/./node_modules/@premieroctet/next-admin/dist/utils/prisma.js:368:47)
    at async getPropsFromParams (webpack-internal:///(rsc)/./node_modules/@premieroctet/next-admin/dist/utils/props.js:80:44)
    at async AdminPage (webpack-internal:///(rsc)/./src/app/admin/[[...nextadmin]]/page.js:27:19) {
  clientVersion: '5.21.1'
}

Browsers

Chrome

cregourd commented 3 weeks ago

Hi @ZiggyQubert I can't reproduce at the moment using our example application, can you give me the value or URL (especially searchParams) to try and identify the problem ?

ZiggyQubert commented 3 weeks ago

if you add these models to your schema on the example app it will have the issue

model Flow {
  id           String        @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  createdAt    DateTime      @default(now())
  name         String
  flowVersions FlowVersion[] @relation("FlowVersion")
}

model FlowVersion {
  id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid

  createdAt DateTime @default(now())
  name      String
  flowId    String?  @db.Uuid
  flow      Flow?    @relation("FlowVersion", fields: [flowId], references: [id], onDelete: Cascade)
}
cregourd commented 3 weeks ago

Hi @ZiggyQubert,

Thanks for the details, I managed to reproduce your problem, it seems to be due to the nullable behavior of this field, a patch is available on v6.1.7 🚀

Feel free to give us more feedback