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

New collection being created when choosing an existing one for a junction #21628

Open
kashike opened this issue Feb 29, 2024 · 1 comment
Open
Labels

Comments

@kashike
Copy link
Contributor

kashike commented Feb 29, 2024

Describe the Bug

Creating a many-to-many relationship field that utilizes an existing junction collection works successfully, however Directus still creates a new collection/table which is then not used.

I've traced this down to the following area:

The if (!junctionCollection || collectionExists(junctionCollection)) check specifically is where the logic fails, as the collection name being checked is not the one that is actually being used for the junction.

To Reproduce

  1. Insert the following data:
create table issue_abc
(
  id   uuid not null primary key default gen_random_uuid(),
  name text not null
);

create table issue_def
(
  id   uuid not null primary key default gen_random_uuid(),
  name text not null
);

create table issue_abc_issue_def
(
  id           serial primary key,
  issue_abc_id uuid not null references issue_abc (id) on delete cascade,
  issue_def_id uuid not null references issue_def (id) on delete cascade
);

insert into issue_abc (name) values ('ABC');
insert into issue_def (name) values ('DEF');
  1. Import the Issue Abc and Issue Def collections in the Directus UI.
  2. In the Issue Abc collection, create a new field using the advanced creation modal of type Many to Many Relationship as follows :
  • Schema
    • Key: thing
  • Relationship
    • Related Collection: issue_def
    • Junction Collection: issue_abc_issue_def (remove the _1 by default at the end)
    • Relational Triggers: all set to Delete the issue_abc_issue_def item (cascade)
  1. Check your database, and you'll see that a new issue_abc_issue_def_1 table has been created.
  2. Go to the content editor, Issue Abc collection, and edit the item to add a value to the Thing field.
  3. Check your database, and you'll see that the relationship has been created in the issue_abc_issue_def table, as is expected.

Directus Version

v10.9.3

Hosting Strategy

Self-Hosted (Docker Image)

@luigigorlero
Copy link

This also seems to affect M2A

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

No branches or pull requests

4 participants