-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
joinable!
not generated when FKs in different tables have the same name
#3646
Comments
Thanks for opening this issue. I can reproduce that issue, but I do not see a easy way to fix it. Diesel queries the postgresql information_schema for database introspection information, including information about the foreign key constraints. In detail: We use the
The relevant query is here: diesel/diesel_cli/src/infer_schema_internals/pg.rs Lines 183 to 197 in c5a9f7b
I'm happy to receive suggestions (or PR's) how to resolve that issue. |
Thanks for looking into this! I'm not sure what the issue is, but when I inspect the database, I do see the FK in both |
Could you share the relevant entries there?
It cannot use the table name there as |
Oh, you're right, for some reason I thought I saw it there... Still, looking at the view I see this: consent=# SELECT t.*
consent-# FROM information_schema.referential_constraints t;
constraint_catalog | constraint_schema | constraint_name | unique_constraint_catalog | unique_constraint_schema | unique_constraint_name | match_option | update_rule | delete_rule
--------------------+-------------------+-----------------+---------------------------+--------------------------+------------------------+--------------+-------------+-------------
consent | public | fk_data_kind | consent | public | kinds_pkey | NONE | NO ACTION | NO ACTION
consent | public | fk_data_kind | consent | public | kinds_pkey | NONE | NO ACTION | NO ACTION
... <2 other unrelated rows>
(4 rows) |
Well the problem there is that, while |
Sorry, I think there's a misunderstanding here - the FK does show up in consent=# SELECT t.* FROM information_schema.table_constraints t WHERE table_name='data_mapping';
constraint_catalog | constraint_schema | constraint_name | table_catalog | table_schema | table_name | constraint_type | is_deferrable | initially_deferred | enforced | nulls_distinct
--------------------+-------------------+-----------------------+---------------+--------------+--------------+-----------------+---------------+--------------------+----------+----------------
consent | public | data_mapping_pkey | consent | public | data_mapping | PRIMARY KEY | NO | NO | YES |
consent | public | fk_data_kind | consent | public | data_mapping | FOREIGN KEY | NO | NO | YES |
consent | public | 2200_33044_1_not_null | consent | public | data_mapping | CHECK | NO | NO | YES |
consent | public | 2200_33044_2_not_null | consent | public | data_mapping | CHECK | NO | NO | YES |
(4 rows) I have also confirmed that using the Edit: I've updated the issue title/description to reflect this, and also added a test that reproduces this in #3650. |
joinable!
joinable!
not generated when FKs in different tables have the same name
Fixed by #3650 |
add test reproducing diesel-rs#3646
Setup
Versions
postgres:latest
Docker image)Feature Flags
Problem Description
Having two tables with a foreign key that has the same name causes
joinable
to not be generated.What are you trying to accomplish?
This is the "first" migration in a project, and I have the following table definitions:
When I run the migration, the generated
schema.rs
contains thetable!
definitions but not thejoinable!
.What is the expected output?
What is the actual output?
No
joinable!
.Are you seeing any additional errors?
Not an additional error, but some more information...
Changing the constraint name so that it doesn't match between the two tables does generate the
joinable!
. Similarly, when switching to "inline" FKs on the column definitions ("data_kind_id__kind_id" INT NOT NULL REFERENCES kinds (kind_id)
) works as well, because the generated constraint names do not match.Steps to reproduce
Fresh database, create a migration with the tables above, and apply the migration.
Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: