0

I have a typical relationship between Users and Posts

Users:

export const Users: CollectionConfig = {
 slug: 'users',
 admin: {
 useAsTitle: 'email',
 },
 auth: true,
 fields: [
 {
 type: 'relationship',
 name: 'posts',
 relationTo: 'posts',
 hasMany: true,
 }
 ],
}

adn Posts:

import type { CollectionConfig } from 'payload'
export const Posts: CollectionConfig = {
 slug: 'posts',
 admin: {
 useAsTitle: 'title',
 defaultColumns: ['featuredImage', 'title', 'author', 'createdAt'],
 },
 versions: {
 drafts: {
 autosave: true,
 },
 maxPerDoc: 20,
 },
 timestamps: true,
 fields: [
 {
 type: 'text',
 name: 'title',
 required: true,
 },
 {
 name: 'content',
 type: 'richText',
 required: true,
 },
 {
 name: 'slug',
 type: 'text',
 unique: true,
 index: true,
 hooks: {
 beforeValidate: [
 ({ value, data }) => value ?? data?.title?.toLowerCase().replace(/\s+/g, '-'),
 ],
 },
 },
 {
 name: 'featuredImage',
 type: 'upload',
 relationTo: 'media',
 required: false,
 },
 {
 name: 'categories',
 type: 'relationship',
 relationTo: 'categories',
 hasMany: true,
 },
 {
 name: 'author',
 type: 'relationship',
 relationTo: 'users',
 required: true,
 hasMany: false,
 index: true,
 },
 ],
}

And if creating the first user I get a dropdown field labeled 'Posts' with no options.

enter image description here

I'd like to know if something's wrong and what does this mean.

Payload config:

// storage-adapter-import-placeholder
import { postgresAdapter } from '@payloadcms/db-postgres'
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import path from 'path'
import { buildConfig } from 'payload'
import { fileURLToPath } from 'url'
import sharp from 'sharp'
import { Users } from './collections/Users'
import { Media } from './collections/Media'
import { Posts } from '@/collections/Posts'
import { Categories } from '@/collections/Categories'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export default buildConfig({
 admin: {
 user: 'users',
 importMap: {
 baseDir: path.resolve(dirname),
 },
 },
 collections: [Posts, Users, Media, Categories],
 editor: lexicalEditor(),
 secret: process.env.PAYLOAD_SECRET || '',
 typescript: {
 outputFile: path.resolve(dirname, 'payload-types.ts'),
 },
 db: postgresAdapter({
 pool: {
 connectionString: process.env.CMS_POSTGRES_URL,
 },
 push: false
 }),
 sharp,
 plugins: [
 payloadCloudPlugin(),
 // storage-adapter-placeholder
 ],
})

Additionally I noticed that the dropdown tries to populate its options with /api/posts getting a 403??

Thanks for helping.

DarkBee
14.4k9 gold badges86 silver badges135 bronze badges
asked Jul 8, 2025 at 3:09
1
  • Yeah the field will show up in the create first user view. Any field on the users collection will appear here. Imagine if you had required fields, you would need those to appear for create. You could use css to hide this field on this view though if you would like. As for the 403, do you have access control defined on your posts collection? Commented Jul 9, 2025 at 3:46

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.