Ticket #7246: 7246.diff
File 7246.diff, 2.7 KB (added by , 16 years ago) |
---|
-
django/db/models/sql/query.py
880 880 881 881 for f, model in opts.get_fields_with_model(): 882 882 if (not f.rel or (restricted and f.name not in requested) or 883 (not restricted and f.null) or f.rel.parent_link):883 (not restricted and f.null)): 884 884 continue 885 885 table = f.rel.to._meta.db_table 886 886 if model: … … 894 894 promote=f.null) 895 895 else: 896 896 alias = root_alias 897 898 # For parent links all tables are already joined in "if model:" clause above 899 # Also we don't need to recurse further along parent links 900 if f.rel.parent_link: 901 continue 902 897 903 alias = self.join((alias, table, f.column, 898 904 f.rel.get_related_field().column), exclusions=used, 899 905 promote=f.null) 900 906 used.add(alias) 901 907 self.related_select_cols.extend([(alias, f2.column) 902 for f2 in f.rel.to._meta. fields])903 self.related_select_fields.extend(f.rel.to._meta. fields)908 for f2 in f.rel.to._meta.local_fields]) 909 self.related_select_fields.extend(f.rel.to._meta.local_fields) 904 910 if restricted: 905 911 next = requested.get(f.name, {}) 906 912 else: -
tests/modeltests/model_inheritance/models.py
79 79 def __unicode__(self): 80 80 return u"%s the italian restaurant" % self.name 81 81 82 class Pizza(models.Model): 83 restaurant = models.ForeignKey(ItalianRestaurant) 84 name = models.CharField(max_length=50) 85 86 def __unicode__(self): 87 return u"%s at %s" % (self.name, self.restaurant) 88 82 89 class Supplier(Place): 83 90 customers = models.ManyToManyField(Restaurant, related_name='provider') 84 91 … … 263 270 <Chef: Albert the chef> 264 271 >>> len(db.connection.queries) 265 272 3 273 >>> restaurant = ItalianRestaurant.objects.all()[0] 274 >>> pizza1 = Pizza.objects.create(name='Margherita', restaurant=restaurant) 275 >>> pizza2 = Pizza.objects.create(name='Capricciosa', restaurant=restaurant) 276 >>> len(Pizza.objects.all().select_related()) 277 2 278 >>> len(Pizza.objects.all().select_related('restaurant')) 279 2 280 >>> Pizza.objects.all().select_related()[0] 281 <Pizza: Capricciosa at True the italian restaurant> 266 282 >>> settings.DEBUG = False 267 283 268 284 """}