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

Foreign Key column being ignored #21605

Open
kashike opened this issue Feb 28, 2024 · 1 comment
Open

Foreign Key column being ignored #21605

kashike opened this issue Feb 28, 2024 · 1 comment

Comments

@kashike
Copy link
Contributor

kashike commented Feb 28, 2024

Describe the Bug

It's possible to have a column in a table that references a column that is not a primary key in another table, however Directus ignores the column being referenced and always uses the primary key.

To Reproduce

  1. Import the following into a database:
create table table_a
(
  id uuid not null primary key default gen_random_uuid(),
  foo uuid unique
);

create table table_b
(
  id        uuid not null primary key default gen_random_uuid(),
  something uuid not null references table_a (foo)
);
  1. Startup Directus and go to Settings -> Data Model and import Table A.

  2. Import Table B, opening the configuration page for the something field and navigating to the Relationship tab. You'll see that Directus thinks that the Related Collection (table_a) field is id when it should be foo.

  3. Set the Interface -> Many to One -> Display Template value to {{foo}}, and the Display -> Related Values -> Display Template value to {{foo}}.

  4. Insert an entry into Table A.

  5. Attempt to insert an entry into Table B selecting the item from Table A as the value for Something

  6. Click save, and be given the following error:

{
  "message": "Invalid foreign key for field \"something\" in collection \"table_b\".",
  "extensions": {
    "code": "INVALID_FOREIGN_KEY",
    "collection": "table_b",
    "field": "something"
  }
}

Directus Version

v10.9.3

Hosting Strategy

Self-Hosted (Docker Image)

@paescuj
Copy link
Member

paescuj commented Feb 28, 2024

This is similar to #21592 as it is also not supported, however that as well means it shouldn't be possible to set up like this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants