Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Getting QueryError on collection called Posts in Multi-Tenant

default discord avatar
techinvertedlast year
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
    notchrlast year

    Is the error coming from this collection in particular?

  • default discord avatar
    techinvertedlast year
    @1049775120559898725

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

  • default discord avatar
    notchrlast year

    hmm



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

  • default discord avatar
    techinvertedlast year
    @1049775120559898725

    yup. That's the only reference

  • default discord avatar
    notchrlast year

    how are you importing tenants?



    @149873958760480769

    sorry for the delay

  • default discord avatar
    techinvertedlast year

    Hey

    @1049775120559898725

    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

    @1049775120559898725

    I've resolved this issue. I hadn't added tenant under fields.

    :whatthehell:

    Thank you so much for the help

    @1049775120559898725

    fields: [ //other fields tenant, ],

    @1049775120559898725

    Do you know how to tackle this

    https://ptb.discord.com/channels/967097582721572934/1141677560846094518
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.