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

Batch updating entries with m2m field results in duplicates #15034

Open
icelandcruiser opened this issue Aug 11, 2022 · 10 comments
Open

Batch updating entries with m2m field results in duplicates #15034

icelandcruiser opened this issue Aug 11, 2022 · 10 comments
Labels

Comments

@icelandcruiser
Copy link

Describe the Bug

Batch updating entries which include a many to many field results in duplicates if options are added to it.

To Reproduce

Create a new collection called Items and another collection named Options. Add a new Input field to Options called Name. Create at least 2 new entries in Options with Name set to something unique. Create a new Many to Many field in Items and set Options as the related collection.

Create a few entries in Items and select some Options. You should not be able to add Options you have already selected.

Go to the overview table of Items and select all entries. Open the batch editor and choose one or more Options and hit save. The entries of Items should contain the Options which were added individually and in addition to that all the Options which were selected in the batch editor.

Directus.Bug.Report.Batch.Editing.M2M.mov

Errors Shown

No response

What version of Directus are you using?

9.15.1

What version of Node.js are you using?

Default Directus Docker Image

What database are you using?

Default Directus Docker Image

What browser are you using?

Chrome

How are you deploying Directus?

Docker

@rijkvanzanten
Copy link
Member

This is technically working as intended, but I agree that the behavior is unexpected and should be considered a bug 👍🏻

@Nitwel
Copy link
Member

Nitwel commented Aug 24, 2022

I'm wondering how we would go ahead and fix that. As to fix it in the api we would have to either introduce a batch mode to relational interfaces or we would have to fix that inside the api.

@rijkvanzanten
Copy link
Member

@Nitwel We might be able to add a "delete everything" flag next to the create calls for the batch mode in the app side, something like:

{
  create: [{ title: 'example' }],
  delete: ['*']
}

@Nitwel
Copy link
Member

Nitwel commented Aug 24, 2022

I don't think that is a solution either as there could be information on the junction table that would get lost in the process. My intuition would be to add ones that dont exist yet and delete the ones, that existed, but are not selected in the batch mode.

@rijkvanzanten
Copy link
Member

My intuition would be to add ones that dont exist yet and delete the ones, that existed, but are not selected in the batch mode.

Hmm yeah, though the goal here is to set all items in the batch to the same result, so maybe we'd have to clear out all existing linked junction items after all 🤔

@domdus
Copy link

domdus commented Sep 1, 2022

We are distributing content (articles, videos, images) to different "services" (customers). So the content collections have a m2m to services collection. During batch you don't know what items have a service assigned already, so "batch-adding" it again leads to duplicates sometimes.
I would vote for a add ones that dont exist yet as a fix.

Also I see how a delete everything or a delete the ones, that existed, but are not selected in the batch mode would solve the duplication totally, but here a concern:

A main use case we have is -> launching a new service:
That means hundrets of content items get selected to be batch-updated to add a new (created) service.
In this case a delete everything would basically drop all items services. (that may have been assigned to 1-n services/customers already)

So I guess one expectation is to "add", not to overwrite m2ms during batch, but there are many different cases for sure.
Maybe it needs both: add or overwrite (delete) option in batch edit drawer.

@bcartier
Copy link

bcartier commented Sep 24, 2022

It seems to me that the existing wording and functionality already sets the expectation of batch editing not batch adding. The way to works for other multi-value fields like checkboxes etc is that it completely replaces all values (checked and unchecked ) with the newly specified selections (checked or not checked). Not selecting a relationship in the Bulk Edit is just as meaningful as selecting one.

Choosing to Bulk edit relationships and having the system leave existing relationships as-is but adding only newly selected is a bug. It only implements half of the advertised intent of the UI.

If the use case exists to "Batch add" (as opposed to "Batch edit"), then that should be accomplished with a new feature or perhaps a Flow or something.

@rijkvanzanten
Copy link
Member

I agree. The expectation is set that the interface will update every selected item to the same value, rather than modifying the relations on top of what's already there.

@rijkvanzanten
Copy link
Member

Linear: ENG-210

@bcartier
Copy link

This is a dangerous bug... has it been addressed in v9 or v10?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📋 Backlog
Development

No branches or pull requests

5 participants