[patch] select_related() additions (depth=N, fields=)
|Reported by:||David Cramer <dcramer@…>||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||matthias@…, gary.wilson@…, gabor@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||yes|
While I was happy with django's db api, to an extent, it did not have everything needed for the basics. So here is a quick solution to some related fields using select_related().
It adds to parameters to select_related(), depth, and fields.
depth: A numerical field and represents the recursion depth for keys, by default, django recurses infinitely on any keys that are not blank=True
fields: A list of field names in the base model to join with. It does not support children, ie relatedfieldfieldname, but I'd like to add this later, this will also set depth to 1.
I've done several unit tests (several being all of curse-gaming.com) and we're pushing the changes live on the site now. It's helping performance out quite a bit in areas where it was too difficult to manually join with just one other table, or areas where we just wanted top level results.
Change History (27)
Changed 8 years ago by David Cramer <dcramer@…>
comment:1 Changed 8 years ago by Jeremy Dunck <jdunck@…>
- Summary changed from select_related() additions (depth=N, fields=) to [patch] select_related() additions (depth=N, fields=)
comment:5 Changed 8 years ago by SmileyChris
- Needs documentation set
- Needs tests set
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Accepted