Skip to content

useAsTitle virtual field validation is skipped if collection has auth enabled #16142

@VeiaG

Description

@VeiaG

Describe the Bug

I have virtual field name on users which was joining first and last name. Using it as title works, but searching for users inside relationship fields is broken this way, because virtual field cannot be queried inside where query .

When i searched how to fix this, where this issue was coming from, i encountered that suppossedly you can't use virtual field in useAsTitle. But i was wondering, why i didn't got any validation errors, it was clearly working. And then i found this -> https://github.com/payloadcms/payload/blob/main/packages/payload/src/collections/config/useAsTitle.ts#L35

This validation for virtual field is skipped if collection is auth-enabled.

Link to the code that reproduces this issue

https://github.com/VeiaG/payload-3-reproductions/tree/relationship-repro

Reproduction Steps

I don't think reproduction is needed here, because mistake is clear. But, you can clone reproduction repository, and try to start it -> The field "name" specified in "admin.useAsTitle" in the collection "test-collection" is virtual. A virtual field can be used as the title only when linked to a relationship field.

But, if you remove useAsTitle in test collection, everything works (excpet searching inside relatioship fields). But it should throw error too, because auth collection users has same useAsTitle logic as test collection

Which area(s) are affected?

area: core

Environment Info

Binaries:
  Node: 22.16.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.19.0
Relevant Packages:
  payload: 3.81.0
  next: 15.4.7
  @payloadcms/db-sqlite: 3.81.0
  @payloadcms/drizzle: 3.81.0
  @payloadcms/email-nodemailer: 3.81.0
  @payloadcms/graphql: 3.81.0
  @payloadcms/live-preview: 3.81.0
  @payloadcms/live-preview-react: 3.81.0
  @payloadcms/next/utilities: 3.81.0
  @payloadcms/payload-cloud: 3.81.0
  @payloadcms/plugin-nested-docs: 3.81.0
  @payloadcms/richtext-lexical: 3.81.0
  @payloadcms/translations: 3.81.0
  @payloadcms/ui/shared: 3.81.0
  react: 19.2.0
  react-dom: 19.2.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions