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
Proper handling of custom m2m relationships #1093
Proper handling of custom m2m relationships #1093
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1093 +/- ##
==========================================
- Coverage 97.23% 97.08% -0.16%
==========================================
Files 23 23
Lines 1231 1236 +5
Branches 199 202 +3
==========================================
+ Hits 1197 1200 +3
Misses 16 16
- Partials 18 20 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
…les for m2m relationships.
d7cefbb
to
2f759b2
Compare
for more information, see https://pre-commit.ci
Find the name of the field in the through table. This is necessary for the | ||
custom through tables where Django conventions don't apply. | ||
""" | ||
foreign_keys = filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the case where m2m has through_fields
https://github.com/django/django/blob/main/django/db/models/fields/reverse_related.py#L383
@PiotrKurnik I saw you tagged #1079 on this issue but this PR but it doesn't seem to allow adding custom table names for each of the m2m fields. Am I missing how to set the custom table names? |
Looks like #1218 fixes this issue - at least the tests added in this PR and the example provided in #1094 now work without any errors, and they stop working when reverting the changes made in Please reopen if it turns out that the issue was not resolved 🙂 |
django-simple-history
does not work with customthrough
tables for m2m relations.Description
Code snippet below illustrates the issue. There are assumptions to the name of the fields in through tables for m2m tables.
For the default through tables it works, but for the custom ones it does not.
If you try to save object of
PageArticle
you will see:Related Issue
#1079
Motivation and Context
We need to use model introspection to find the correct field name and not to relate on model name.
How Has This Been Tested?
Unit test has been added.
Screenshots (if appropriate):
Types of changes
Checklist:
pre-commit run
command to format and lint.AUTHORS.rst
CHANGES.rst