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

[ci skip] Suggest using composite primary key on join tables in :through associations #49218

Merged
merged 1 commit into from Sep 11, 2023

Conversation

nvasilevski
Copy link
Contributor

Currently Rails suggests to create tables with no primary key to be used as a join table for a has_and_belongs_to_many association which makes sense since there is no model backing the table

However for a join table with a backing model it may make more sense to choose a composite primary key on both foreign_key_1, foreign_key_2 column instead of unnecessarily keeping the id column .

This PR adds a suggestion to consider composite primary key for join tables that are represented by a whole model

We are utilizing this suggestion ourselves in the Rails test suite - #49206

@rails-bot rails-bot bot added the docs label Sep 11, 2023
@eileencodes eileencodes merged commit 0bddf35 into rails:main Sep 11, 2023
3 checks passed
@eileencodes eileencodes deleted the suggest-cpk-for-join-tables branch September 11, 2023 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants