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: Incorrect Parent Relationship Assignment When Adding a New Document #8388

Closed
tobiasiv opened this issue Sep 24, 2024 · 4 comments · Fixed by #9381
Closed

Join Field: Incorrect Parent Relationship Assignment When Adding a New Document #8388

tobiasiv opened this issue Sep 24, 2024 · 4 comments · Fixed by #9381

Comments

@tobiasiv
Copy link

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: 9.7.0
Relevant Packages:
  payload: 3.0.0-beta.108
  next: 15.0.0-canary.160
  @payloadcms/db-mongodb: 3.0.0-beta.108
  @payloadcms/db-postgres: 3.0.0-beta.108
  @payloadcms/graphql: 3.0.0-beta.108
  @payloadcms/next/utilities: 3.0.0-beta.108
  @payloadcms/richtext-lexical: 3.0.0-beta.108
  @payloadcms/richtext-slate: 3.0.0-beta.108
  @payloadcms/translations: 3.0.0-beta.108
  @payloadcms/ui/shared: 3.0.0-beta.108
  react: 19.0.0-rc-5dcb0097-20240918
  react-dom: 19.0.0-rc-5dcb0097-20240918
Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 19.6.0: Tue Feb 15 21:39:11 PST 2022; root:xnu-6153.141.59~1/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 4

Describe the Bug

I'm working with Postgres and using numeric IDs. When adding a new entry to a join-field-table, the parent relationship should be automatically set for the new entry. However, the parent is not being set correctly. When I attempt to save the newly created record, I get the following error: "This relationship field has the following invalid relationships: 1 0."
This issue might be related to the ID type, I've experienced a similar error in the past.

Reproduction Steps

  1. Clone payload-3.0-demo
  2. Update package.json as mentioned in PR #8323
  3. Switch the database from MongoDB to Postgres
  4. Add a relationship field to the pages collection
{
  slug: 'pages',
  admin: {
    useAsTitle: 'title',
  },
  fields: [
    {
      name: 'title',
      type: 'text',
    },
    {
      name: 'content',
      type: 'richText',
    },
    {
      name: 'user',
      type: 'relationship',
      relationTo: 'users',
    },
  ],
},
  1. Add join field to the users collection
{
  slug: 'users',
  auth: true,
  access: {
    delete: () => false,
    update: () => false,
  },
  fields: [
    {
      name: 'pages',
      type: 'join',
      collection: 'pages',
      on: 'user',
    },
  ],
},
  1. Open a user document and click the "Create new Page" button.
  2. A drawer opens to create a new document, but it sets the parent relationship incorrectly. The label of the relationship field appears as "Untitled - ID: 1". If you try to save the document, you get an error.

Adapters and Plugins

No response

@tobiasiv tobiasiv added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Sep 24, 2024
@akhrarovsaid
Copy link
Contributor

Hey @tobiasiv,

I was able to reproduce your issue. However, in order to reproduce this issue, you have to disable the drafts: { autosave: <number> } setting in the collection configuration.

In the process of reproducing your issue I stumbled upon two other issues that seem related to the creation of documents from the "Join" type Drawer component.

  1. Conditional fields are late/lazy to re-render. I can confirm this by selecting the Low Impact hero type in the pages collection and seeing that the media field isn't being hidden away.
  2. With draft autosaves the new document is stuck on Saving... and never actually saves a draft or creates a DB entry - likely due to the aforementioned issue where the error reads: This relationship field has the following invalid relationships: {Id} 0, where {Id} is the numerical id of the relation object

I'm attaching two videos to show these issues in practice.

chrome_2024-09-26_15-48-38.mp4

The above video shows a reproduction of this issue, as well as the issue mentioned in (1).

chrome_2024-09-26_15-52-05.mp4

This second video shows (2), and requires you have autosave enabled. In the video, I have an autosave interval of 100. No errors were generated.

@tobiasiv
Copy link
Author

Hey @DanRibbens - It seems this issue might have been missed. Could you please take a look? I’d really appreciate it!

@denolfe denolfe removed the v3 label Nov 19, 2024
@jacobsfletch
Copy link
Member

Hey @tobiasiv this was fixed in #9381 and has been released as of v3.0.2. Let me know if you're still experiencing issues after upgrading. And thank you @akhrarovsaid for confirming this in such detail.

With draft autosaves the new document is stuck on Saving...

This was likely fixed in #9364. Join fields with autosave-enabled collections were broken in a few ways. This likely also fixes the issue you've described about conditional fields but I'd need you to report back on that one. Feel free to open new ticket(s) for that if needed.

@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Nov 23, 2024
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.

4 participants