-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Fix M2M relations for models with composite keys #996
Conversation
Don't query the columns in the M2M table that are used as foreign keys for the joined table. We only need the columns from the base table.
We need to ensure that we follow the same ordering of the base table column names and values when constructing the JOIN query, as well as when storing the base values.
We can construct the key by only looking at the relevant columns in the M2M table, we shouldn't look at the columns from the joined table.
The first `len(m.rel.M2MBaseFields)` columns are always coming from the M2M table, as specified in the M2M join query in function `relationJoin.m2mQuery()`. Thus we compare the `scanIndex` to this value. Additionally, more columns can be requested by the caller, and so the checking the `m.table.FieldMap` is still relevant.
1395704
to
9f823aa
Compare
The new Since this feature is non-breaking and only fails for a single, arguably niche, target, I'd be happy to see it merged as is. For MS SQL Server backends, we can add a runtime error during the @vmihailenco what are your thoughts? |
@ygabuev thanks. I've skipped MSSQL tests for now.
I think this is totally fine, but let's not block this PR because of MSSQL. |
This PR adds support for M2M relations with composite keys. This feature was probably supposed to be working previously, but was not tested and turned out to be buggy. Existing functionality is not affected, according to the tests.
Commits:
Closes #992.