On Wed, Jun 16, 2010 at 11:55 PM, ryan <writepyt...@gmail.com> wrote: > I noticed this first in the Django Admin. If you have 100 rows in > Table A, and 5 of those have a foreign key entry pointing to a > nonexistent item in Table B, rather than throwing an error, the admin > displays 95. This happens if you set > list_select_related = True, or if one of the list_display fields is a > ForeignKey. (http://docs.djangoproject.com/en/dev/ref/contrib/admin/ > #django.contrib.admin.ModelAdmin.list_select_related) > > So you can reproduce this by calling select_related. But my question > is "How does this happen?". What are the lines of code that remove > the 5 rows with broken foreign keys from the queryset? I've been > digging through the Django codebase and can't find it.
A select_related() is a query that returns all the rows from table A that have corresponding rows in table B. If a row in A doesn't have a corresponding row in B (which includes the case where A points to a non-existent row in B), then the row from A isn't included, either. This isn't thing that Django implements - it's a function of the way the underlying relational database works. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.