Getting QueryError on collection called Posts in Multi-Tenant

default discord avatar
techinverted
last month
6

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', }, }, ], }
  • default discord avatar
    notchr
    last month

    Is the error coming from this collection in particular?

  • default discord avatar
    techinverted
    last month

    @notchr yes, I get it when I try to open posts or reusablecontent

    admin.png
  • default discord avatar
    notchr
    last month

    hmm



    The only reference to tenant in that collection is in the access controls right?

  • default discord avatar
    techinverted
    last month

    @notchr yup. That's the only reference

  • default discord avatar
    notchr
    last month

    how are you importing tenants?



    @techinverted sorry for the delay

  • default discord avatar
    techinverted
    last month

    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.

    :whatthehell:


    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/1141677560846094518
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.