[Bug]: @adminjs/relations many-to-many with Prisma
lpbonomi opened this issue · comments
Contact Details
No response
What happened?
Trying to use the @adminjs/relations add on with a many-to-many relationship but get the following error:
TypeError: Cannot read properties of null (reading 'type')
[1] at file:///Users/luispe/Repos/ultradrop-app/apps/admin/node_modules/@adminjs/prisma/lib/utils/converters.js:28:88
[1] at Array.reduce (<anonymous>)
[1] at convertFilter (file:///Users/luispe/Repos/ultradrop-app/apps/admin/node_modules/@adminjs/prisma/lib/utils/converters.js:27:36)
[1] at Resource.find (file:///Users/luispe/Repos/ultradrop-app/apps/admin/node_modules/@adminjs/prisma/lib/Resource.js:49:20)
[1] at manyToManyHandler (file:///Users/luispe/Repos/ultradrop-app/node_modules/@adminjs/relations/lib/actions/many-to-many/many-to-many.handler.js:1:648)
[1] at file:///Users/luispe/Repos/ultradrop-app/node_modules/@adminjs/relations/lib/actions/relations.handler.js:1:840
[1] at file:///Users/luispe/Repos/ultradrop-app/node_modules/adminjs/lib/backend/decorators/action/action-decorator.js:98:90
I've tried using what @dziraf suggested in #1595 and it succeeds to display (but not to add any records) the many-to-many fields whenever there are none but fails otherwise with the error:
[1] PrismaClientValidationError:
[1] Invalid `prisma.collectionAsset.findMany()` invocation:
[1]
[1] {
[1] where: {
[1] collectionId: 7
[1] },
[1] skip: 0,
[1] take: 10,
[1] orderBy: {
[1] asset: "desc"
[1] ~~~~~~
[1] }
[1] }
[1]
[1] Argument `asset`: Invalid value provided. Expected FileOrderByWithRelationInput, provided String.
[1] at ti (/Users/luispe/Repos/ultradrop-app/node_modules/@prisma/client/runtime/library.js:118:5888)
[1] at si.handleRequestError (/Users/luispe/Repos/ultradrop-app/node_modules/@prisma/client/runtime/library.js:125:6473)
[1] at si.handleAndLogRequestError (/Users/luispe/Repos/ultradrop-app/node_modules/@prisma/client/runtime/library.js:125:6151)
[1] at si.request (/Users/luispe/Repos/ultradrop-app/node_modules/@prisma/client/runtime/library.js:125:5859)
[1] at async l (/Users/luispe/Repos/ultradrop-app/node_modules/@prisma/client/runtime/library.js:130:9805)
[1] at async Resource.find (file:///Users/luispe/Repos/ultradrop-app/apps/admin/node_modules/@adminjs/prisma/lib/Resource.js:48:25)
[1] at async manyToManyHandler (file:///Users/luispe/Repos/ultradrop-app/node_modules/@adminjs/relations/lib/actions/many-to-many/many-to-many.handler.js:1:640)
[1] at async ActionDecorator.handler (file:///Users/luispe/Repos/ultradrop-app/node_modules/adminjs/lib/backend/decorators/action/action-decorator.js:56:19)
[1] at async ApiController.recordAction (file:///Users/luispe/Repos/ultradrop-app/node_modules/adminjs/lib/backend/controllers/api-controller.js:149:28)
[1] at async file:///Users/luispe/Repos/ultradrop-app/node_modules/@adminjs/express/lib/buildRouter.js:24:22
Bug prevalence
Whenever I go to the page using this feature
AdminJS dependencies version
"@adminjs/express": "^6.1.0",
"@adminjs/prisma": "^5.0.1",
"@adminjs/relations": "^1.0.0",
"adminjs": "^7.5.9",
What browsers do you see the problem on?
No response
Relevant log output
No response
Relevant code that's giving you issues
model Collection {
id Int @id @default(autoincrement())
CollectionAssets CollectionAsset[]
more fields...
@@map("collections")
}
model File {
id Int @id @default(autoincrement())
AssetOf CollectionAsset[]
more fields...
@@map("files")
}
model CollectionAsset {
collection Collection @relation(fields: [collectionId], references: [id])
collectionId Int @map("collection_id")
asset File @relation(fields: [assetId], references: [id])
assetId Int @map("asset_id")
more fields...
@@id([collectionId, assetId])
@@map("collection_assets")
}
@lpbonomi this should be fixed via @adminjs/prisma
5.0.2:
https://github.com/SoftwareBrothers/adminjs-prisma/releases/tag/v5.0.2
Additionally, you can install @adminjs/relations
1.0.1 which allows you to also sort M:N tables if using Prisma. This isn't currently possible with other adapters due to their limitations.