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

Use correct key in unconventional associations #2292

Merged
merged 4 commits into from
Apr 6, 2023

Conversation

pablobm
Copy link
Collaborator

@pablobm pablobm commented Nov 29, 2022

A fix for a bug that you can reproduce right now easily: visit the demo app (https://administrate-prototype.herokuapp.com/admin/customers), select any customer, edit, save, and the customer will lose their territory value.

This is a bug introduced with #1633, where I failed to use associated_primary_key to refer to the key on the other side of a foreign key.

Specifically in our demo app, the Customer model belongs to Country . However instead of the conventional matching of Customer#country_id to Country#id, it should match Customer#country_code to Country#code. While foreign_key gives us country_code, we wrongly use primary_key for the counterpart. Instead we should use association_primary_key which gives us code.

Fixes #2169

@pablobm pablobm force-pushed the associated-primary-key branch 4 times, most recently from 59e82d0 to fdcf67a Compare November 29, 2022 10:42
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.

POST to create through controller with different FK constraint than 'id' fails
1 participant