Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » select_related removes broken Foreign Keys, but How? [RSS Feed]

#1 June 16, 2010 16:55:49

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

select_related removes broken Foreign Keys, but How?


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.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 17, 2010 00:51:38

Russell K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

select_related removes broken Foreign Keys, but How?


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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » select_related removes broken Foreign Keys, but How? [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support