Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join field breaks when put on collection with versions #9369

Closed
alexanderbnelson opened this issue Nov 20, 2024 · 5 comments · Fixed by #9370
Closed

Join field breaks when put on collection with versions #9369

alexanderbnelson opened this issue Nov 20, 2024 · 5 comments · Fixed by #9370
Assignees

Comments

@alexanderbnelson
Copy link

alexanderbnelson commented Nov 20, 2024

Describe the Bug

Join field breaks when put on a collection with versions. For example, Pages have a relation to Posts. Posts join to Pages. Both collections have versions. This error shows up [ Server ] Error: column pages_rels._posts_v_id does not exist

It could be that versions on both are required for the bug to present itself. Join works if the collection being joined TO (Pages in this example) has versions and Posts doesn't.

Link to the code that reproduces this issue

https://github.com/alexanderbnelson/payload-example

Reproduction Steps

  • Log into admin
  • Click on the posts collection

View the code for the posts collection config.
https://github.com/alexanderbnelson/payload-example/blob/main/src/collections/Posts/index.ts

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
  Node: 20.11.0
  npm: 10.9.0
  Yarn: 1.22.19
  pnpm: 9.13.2
Relevant Packages:
  payload: 3.0.1
  next: 15.0.3
  @payloadcms/db-postgres: 3.0.1
  @payloadcms/email-nodemailer: 3.0.1
  @payloadcms/graphql: 3.0.1
  @payloadcms/live-preview: 3.0.1
  @payloadcms/live-preview-react: 3.0.1
  @payloadcms/next/utilities: 3.0.1
  @payloadcms/payload-cloud: 3.0.1
  @payloadcms/plugin-form-builder: 3.0.1
  @payloadcms/plugin-nested-docs: 3.0.1
  @payloadcms/plugin-redirects: 3.0.1
  @payloadcms/plugin-search: 3.0.1
  @payloadcms/plugin-seo: 3.0.1
  @payloadcms/richtext-lexical: 3.0.1
  @payloadcms/translations: 3.0.1
  @payloadcms/ui/shared: 3.0.1
  react: 19.0.0-rc-65a56d0e-20241020
  react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:36 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 12
@alexanderbnelson alexanderbnelson added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Nov 20, 2024
@alexanderbnelson alexanderbnelson changed the title Join field break when put on collection with versions Join field breaks when put on collection with versions Nov 20, 2024
@r1tsuu r1tsuu self-assigned this Nov 20, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Nov 20, 2024
Copy link
Contributor

🚀 This is included in version v3.1.0

@alexanderbnelson
Copy link
Author

Just a heads up, I'm still getting the same error after upgrading to 3.1.0. Using the same reproduction.

@r1tsuu
Copy link
Member

r1tsuu commented Nov 23, 2024

Hey Alexander, can you please ensure you are on the latest version? Delete node_modulels / lockfile / .next and reinstall. Because I can't reproduce it, with versions + drafts on both sides + hasMany relationship.

I'm sure I had this specific error in my tests and it was gone after.

@r1tsuu
Copy link
Member

r1tsuu commented Nov 23, 2024

I used this config:

import type { CollectionConfig } from 'payload'

export const versionsSlug = 'versions'

export const Versions: CollectionConfig = {
  slug: versionsSlug,
  fields: [
    {
      name: 'category',
      relationTo: 'categories',
      type: 'relationship',
    },
    {
      name: 'categoryVersion',
      relationTo: 'categories-versions',
      type: 'relationship',
    },
    {
      name: 'categoryVersions',
      relationTo: 'categories-versions',
      type: 'relationship',
      hasMany: true,
    },
  ],
  versions: {
    drafts: true,
  },
}
import type { CollectionConfig } from 'payload'

import { versionsSlug } from './Versions.js'

export const categoriesVersionsSlug = 'categories-versions'

export const CategoriesVersions: CollectionConfig = {
  slug: categoriesVersionsSlug,
  fields: [
    {
      name: 'relatedVersions',
      type: 'join',
      collection: versionsSlug,
      on: 'categoryVersion',
    },
    {
      name: 'relatedVersionsMany',
      type: 'join',
      collection: versionsSlug,
      on: 'categoryVersions',
    },
  ],
  versions: {
    drafts: true,
  },
}

Copy link
Contributor

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants