Opened 12 years ago
Last modified 9 years ago
#20127 new Cleanup/optimization
Unify subquery generation in the ORM — at Initial Version
Reported by: | Anssi Kääriäinen | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There are some different ways for doing subqueries in the ORM currently. Query.split_exclude(), subqueries in deletion, as_nested_sql() and SubqueryConstraint seem to do something similar. Sometimes there are duplicated code paths, sometimes upper layers do something the lower layers will repeat later on.
I think every instance where a subquery constrain is needed should use the SubqueryConstraint either directly, or through QuerySet.filter() or sql.Query.build_filter(). This will allow doing all the somewhat complicated setup in one place.