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

Add print-schema option allow_tables_in_same_query #4500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sgoll
Copy link
Contributor

@sgoll sgoll commented Feb 19, 2025

This adds a new config option to print-schema, i.e. allow_tables_in_same_query (in diesel.toml) or --allow-tables-in-same-query (in CLI).

Setting this option to all_tables, or leaving it unset, remains the current behavior of generating a single invocation of the macro allow_tables_to_appear_in_same_query! that lists all tables in the schema.

Setting this option to fk_related_tables changes this behavior: instead of a single invocation, several invocations are issued, one for each group of tables related to each other through foreign keys.

For example, given the following tables with foreign keys:

users (id)
posts (id, user_id -> users(id))
comments (id, post_id -> posts(id))

sessions (id)
transactions (id, session_id -> sessions(id))

cars (id)
bikes (id)

The following macro invocations are generated:

For all_tables (default):

diesel::allow_tables_to_appear_in_same_query!(
    bikes, cars, comments, posts, sessions, transactions, users);

For fk_related_tables:

diesel::allow_tables_to_appear_in_same_query!(comments, posts, users);
diesel::allow_tables_to_appear_in_same_query!(sessions, transactions);

See #4333 for rationale.

@sgoll
Copy link
Contributor Author

sgoll commented Feb 19, 2025

@weiznich When this gets merged, I can also provide a backport for #4490, or for a future release.

@weiznich weiznich requested a review from a team February 21, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant