Opened 8 years ago

Closed 7 years ago

#5020 closed (fixed)

select_related() implicit joins

Reported by: David Cramer <dcramer@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: qs-rf-fixed
Cc: jesse.lovelace@…, tailofthesun@…, gav@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Add support for implicitly selecting fields to join with.

e.g. MyModel.objects.all().select_related('myforeignkey__user')

See also: http://groups.google.com/group/django-developers/browse_thread/thread/3b33bfe1e625b4ad/06b0a5f39e08d17d#06b0a5f39e08d17d

Attachments (5)

query.py.diff (5.4 KB) - added by David Cramer <dcramer@…> 8 years ago.
models.py (2.0 KB) - added by David Cramer <dcramer@…> 8 years ago.
unit tests
query.py.2.diff (5.5 KB) - added by David Cramer <dcramer@…> 8 years ago.
fixed two minor bugs
query.py.3.diff (5.4 KB) - added by David Cramer <dcramer@…> 8 years ago.
get_cached_row had a slipup
query.py.4.diff (7.3 KB) - added by nostgard <nostgard@…> 8 years ago.
clones and uses _recurse_fields

Download all attachments as: .zip

Change History (17)

Changed 8 years ago by David Cramer <dcramer@…>

comment:1 Changed 8 years ago by David Cramer <dcramer@…>

  • Has patch set
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset

I've attached a patch. It needs unittests and should be tested with trunk.

Changed 8 years ago by David Cramer <dcramer@…>

unit tests

comment:2 Changed 8 years ago by David Cramer <dcramer@…>

  • Needs tests unset

Changed 8 years ago by David Cramer <dcramer@…>

fixed two minor bugs

Changed 8 years ago by David Cramer <dcramer@…>

get_cached_row had a slipup

comment:3 Changed 8 years ago by nostgard <nostgard@…>

The patches provided didn't actually filter my related objects, as_recurse_fields was never saved when cloned and fields= wasn't supplied to the functions. I added a patch with that.

Thanks for doing this. I had rolled my own for this, but it wasn't nearly as clean.

Changed 8 years ago by nostgard <nostgard@…>

clones and uses _recurse_fields

comment:4 Changed 8 years ago by SmileyChris

  • Owner changed from adrian to mtredinnick
  • Triage Stage changed from Unreviewed to Design decision needed

Haven't heard from Malcolm about it yet.

comment:5 Changed 8 years ago by anonymous

  • Cc jesse.lovelace@… added

comment:6 Changed 8 years ago by mtredinnick

  • Keywords qs-rf added

comment:7 Changed 8 years ago by anonymous

  • Cc tailofthesun@… added

comment:8 Changed 8 years ago by gav

  • Cc gav@… added

comment:9 Changed 8 years ago by mtredinnick

(In [6899]) queryset-refactor: Allow specifying of specific relations to follow in
select_related(). Refs #5020.

comment:10 Changed 8 years ago by mtredinnick

  • Keywords qs-rf-fixed added; qs-rf removed

comment:11 Changed 8 years ago by SmileyChris

  • Triage Stage changed from Design decision needed to Accepted

Promoting to accepted: if it's fixed in the queryset refactor then it has obviously an accepted issue.

comment:12 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

Note: See TracTickets for help on using tickets.
Back to Top