Opened 18 years ago

Closed 18 years ago

Last modified 12 years ago

#2820 closed enhancement (wontfix)

selected_related not pulling from GenericRelation's

Reported by: anonymous Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

My assumption is that select_related would pull a GenericRelation but it doesn't seem to.

The problem comes from where I have two models, one being generic, and one being specific. The generic model holds data thats used by several models, and contains an object_id and content_type.

The specific model let's call it Article, and the generic Rating. The end goal would be to be able to do things, such as create a manager, which could perform a left join. The code in SQL would be similar to select * from article_table left join rating_table on a.id = b.object_id and b.content_type_id = x.

The problem is (as far as I can tell) there's no way to do this in django.

Change History (4)

comment:1 by dcramer@…, 18 years ago

To rephrase this a bit, the GenericRelation was the solution to the lack of a solution.

comment:2 by Adrian Holovaty, 18 years ago

Resolution: wontfix
Status: newclosed

I'm completely fine with saying "It doesn't intend to do that." Generic relations are such a special case that it's fair to say they don't need to be able to support select_related.

comment:3 by anonymous, 12 years ago

Easy pickings: unset
UI/UX: unset

Generic relations are same special case as comments to any content on web-sites. So its not "special".

comment:4 by Anssi Kääriäinen, 12 years ago

Django can actually nowadays generate the LEFT OUTER JOIN mentioned in the description. There is a more fundamental problem - GenericRelation isn't unique, you can have multiple comments per content... So, use prefetch_related().

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