Replies: 2 comments 3 replies
-
|
Eliminating polymorphic_ctype_id would simplify correctness and remove an entire class of bugs, but it likely needs to be an opt-in or long-term goal due to migration and third-party dependency concerns. |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
Do we have any plans for assisting users of the library we migrating their dbs in the form of a script or management command for automating the migration. I mean considering the breaking changes scheduled in v5 i wiould assume that their models might break because we no longer using the polymorphic_ctype and other breaking changes? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm starting this discussion as a dumping ground for ideas for how to make polymorphism support first-class in Version 5. What I mean by this is removing the two-phase fetch, check ctype and refetch process with a single fetch process.
My best idea right now:
Django uses
INNER JOINto fetch linked parent tables when fetching multi-table models from a derived model. This also works for polymorphic models when fetching in that direction because the parents must exist. The difference with the polymorphic queries is that you also want to fetch down the hierarchy to find any child model rows. You could do this by addingLEFT OUTER JOINfor every model down the hierarchy as well and basing the python class mapping on one up from the first null table id. A nice side effect of this is that you would also eliminate the need forpolymorphic_ctype_idwhich is a source of a lot of problems - especially in multi-database/multi-tenant setups.What I do not currently understand is how hard this level of customization would be or if there would be any unanticipated side effects because I'm still getting acquainted with Django's ORM internals. Advice from ORM experts would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions