Skip to content

HasMany relationship with localized:true failes to empty the relationship #8132

@michel-jump

Description

@michel-jump

Link to reproduction

No response

Describe the Bug

Relationship

So I have an relationship field which looks like this:

{
    admin: {
        position: "sidebar"
    },
    name: "userGroups",
    label: "Gebruikersgroepen",
    type: "relationship",
    relationTo: UserGroups.slug,
    localized: true,
    required: false,
    hasMany: true,
    index: true,
}

When I remove all the selected userGroups in de Admin panel and save the document it gives a green success toast, but it resets the relationship to the old value.

Some steps I took to test:

  • Select 2 options, save -> ✅
  • Deselect 1 option, 1 option remaining, save -> ✅
  • Deselect 1 option, 0 options remaining, save -> 🚫 (although the toast message says success, it resets the selected options)

createParentField

I have another field, named parent, which is created by the createParentField.
When I query the collection, with that field, with ?where[parent][exists]=false it returns 0 docs, where it should have returned 2 docs.

?where[parent][exists]=true works however..

When it started

It started when I added localized: true. When I remove localized it works again, I can empty the field and query the collection successfully.

What happens here with localized: true?

To Reproduce

  1. Create 2 collections
  2. Add a relationship from one collection to the other with the following properties:
    • localized: true
    • required: false
    • hasMany: true
  3. Go to admin panel
  4. Add a couple docs in the 2 collections
  5. Go to one doc, select a couple options in the relationship field
  6. Save the doc
  7. Edit the relationship field, remove all the selected docs
  8. Save the doc

Payload Version

2.28.0

Adapters and Plugins

db-postgres, plugin-nested-docs, richtext-lexical, bundler-webpack

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triagePossible bug which hasn't been reproduced yetv2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions