All my other collections work fine, other than Posts and ReusableContent.
This is the error
{
"errors": [
{
"name": "QueryError",
"message": "The following path cannot be queried: tenant",
"data": [
{
"path": "tenant"
}
]
}
]
}
This is what the code looks like
export const Posts: CollectionConfig = {
slug: 'posts',
admin: {
useAsTitle: 'title',
// defaultColumns: ['title', 'slug', 'updatedAt'],
},
versions: {
drafts: true,
},
access: {
read: tenants,
readVersions: tenants,
create: loggedIn,
update: tenantAdmins,
delete: tenantAdmins,
},
hooks: {
afterChange: [
({ req: { payload }, doc }) => {
regeneratePage({
payload,
collection: 'posts',
doc,
})
},
],
},
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
name: 'image',
type: 'upload',
relationTo: 'media',
required: true,
},
richText({
name: 'excerpt',
}),
{
name: 'content',
type: 'blocks',
blocks: [Banner, BlogContent, Code, BlogMarkdown, MediaBlock],
required: true,
},
slugField(),
{
name: 'author',
type: 'relationship',
relationTo: 'users',
required: true,
admin: {
position: 'sidebar',
},
},
{
name: 'publishedOn',
type: 'date',
required: true,
admin: {
date: {
pickerAppearance: 'dayAndTime',
},
position: 'sidebar',
},
},
],
}
Is the error coming from this collection in particular?
@notchr yes, I get it when I try to open posts or reusablecontent
hmm
The only reference to tenant in that collection is in the access controls right?
@notchr yup. That's the only reference
how are you importing tenants?
@techinverted sorry for the delay
Hey @notchr this is the import statement :
import { loggedIn } from './access/loggedIn'
import { tenantAdmins } from './access/tenantAdmins'
import { tenants } from './access/tenants'
this is tenants.ts file
import type { Access } from 'payload/types'
import { isSuperAdmin } from '../../utilities/isSuperAdmin'
export const tenants: Access = ({ req: { user }, data }) =>
// individual documents
(data?.tenant?.id && user?.lastLoggedInTenant?.id === data.tenant.id) ||
(!user?.lastLoggedInTenant?.id && isSuperAdmin(user)) || {
// list of documents
tenant: {
equals: user?.lastLoggedInTenant?.id,
},
}
Hi @notchr I've resolved this issue. I hadn't added tenant under fields.
Thank you so much for the help @notchr
fields: [
//other fields
tenant,
],
@notchr Do you know how to tackle this
https://ptb.discord.com/channels/967097582721572934/1141677560846094518Star
Discord
online
Get help straight from the Payload team with an Enterprise License.