Opened 7 years ago

Closed 7 years ago

#12145 closed (duplicate)

select_related() does not work with inherited models

Reported by: Pavel Lang Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: select_related
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Example code:

from django.db import models

class BaseModel(models.Model):
    base_text = models.TextField()

class InheritedA(BaseModel):
    textA = models.TextField()

class InheritedB(BaseModel):
    textB = models.TextField()

Now, when I select BaseModel.objects.all() there is no (possible/easy) way to prefetch related models InheritedA and InheritedB with left outer join and reduce further queries to get each inherited instance of models.

When model inheritance is alowed and modeled as OneToOne relation, it should be possible to do optimization in same sense as select_related() do with foreign keys.

Change History (1)

comment:1 Changed 7 years ago by Alex Gaynor

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: duplicate
Status: newclosed

This is a duplicate of #7270.

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