diesel-rs/diesel

`joinable!` is not generated for two foreign keys referencing the same table

SpekalsG3 opened this issue · 1 comments

Setup

Versions

  • Rust: 1.74.0 (but also 1.73.0)
  • Diesel: 2.1.1
  • Database: postgres
  • Operating System macOS ventura 13.5

Feature Flags

  • diesel: postgres, chrono, postgres_backend, numeric

Problem Description

Diesel doesn't generate joinable! if two foreign keys in a table refence the same table

What are you trying to accomplish?

Define relationship between two tables.

What is the expected output?

diesel::table! {
    child (id) {
        id -> Text,
        parent_one_id -> Text,
        parent_two_id -> Text,
    }
}

diesel::table! {
    parents (id) {
        id -> Text,
    }
}

diesel::joinable!(child -> parents (parent_one_id));
diesel::joinable!(child -> parents (parent_two_id));

diesel::allow_tables_to_appear_in_same_query!(
    child,
    parents,
);

What is the actual output?

diesel::table! {
    child (id) {
        id -> Text,
        parent_one_id -> Text,
        parent_two_id -> Text,
    }
}

diesel::table! {
    parents (id) {
        id -> Text,
    }
}

diesel::allow_tables_to_appear_in_same_query!(
    child,
    parents,
);

Are you seeing any additional errors?

No. Output is as expected:

$ diesel migration redo
Rolling back migration 2023-11-11-003447_create_tables
Running migration 2023-11-11-003447_create_tables

Steps to reproduce

Use this migration (up.sql):

create table parents (
   id text not null primary key
);

create table child (
    id text not null primary key,
    parent_one_id text not null references parents(id),
    parent_two_id text not null references parents(id)
);

Checklist

  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

That's a duplicate of #2432 (and likely other issues).

Closed as duplicate. This is working as designed.