Code

Opened 4 years ago

Closed 4 years ago

#12145 closed (duplicate)

select_related() does not work with inherited models

Reported by: langpavel 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.

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

This is a duplicate of #7270.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.