Hello, I have a CMS made in Payload 2.0 where findById works perfectly, however in Payload 3.0 Beta findById complains that the collection slug does not exist
below is the error
ERROR: APIError: Collection with slug c_distributioncenter cannot be found. Find the operation.
in findLocal (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/local/find.js:15:15)
in BasePayload.find (webpack-internal:///(rsc)/./node_modules/payload/dist/index.js:79:16)
in handleCreateOrUpdate (webpack-internal:///(rsc)/./src/collections/Suppliers/hooks/handleCreateOrUpdate.ts:24:79)
in Suppliers.hooks.beforeChange (webpack-internal:///(rsc)/./src/collections/Suppliers/index.ts:45:95)
in eval (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/create.js:127:26)
Below is my code using findById
const distributionCenter = await payload.findByID({
collection: 'c_distributioncenter',
id: id,
})
It worked correctly! Thanks
This can happen if you do
import payload from 'payload
' and use the imported payload for the local API
Never do that
Make sure to only use payload from req (req.payload) or from somewhere else where it gets passed through
Star
Discord
online
Get dedicated engineering support directly from the Payload team.