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.
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
Marcos Di Paolo
7191 gold badge8 silver badges26 bronze badges
-
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?Jarrod Flesch– Jarrod Flesch2025年07月09日 03:46:39 +00:00Commented Jul 9, 2025 at 3:46