#13073: Duplicate rows when checking ID
------------------------------------------+---------------------------------
 Reporter:  jnadro52                      |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.1       
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 Hello:

 I hope that this is a legitimate bug and I'm not wasting your time with
 something that is a slight misunderstanding of how the Django database
 layer works.  Here we go...

 I have two tables... a table that holds football matchups (texans vs.
 giants, for example) and a table that caches the statistics for the game.
 The table that caches the statistics would have a row per team, so this is
 what the data would look like:


 {{{
 ID       team               opponent              matchup_id
 1        texans             giants                1
 2        giants             texans                1
 }}}


 So now I want to retrieve these two rows by matchup ID.  Lets say the
 model names are "matchup" and "cache".  So, I attempted to go retrieve
 them like so:


 {{{
 caches = cache.objects.filter(matchup=1)
 }}}


 When I do so, I do get two objects returned, but they are both the same
 cache row that is returned.  So I would get a QuerySet containing two
 objects, both of which would have the same primary key.

 What really confused me is that if I added a .distinct() method call to
 the end of that call, I would get the expected results.  If it is the case
 where there is a join occurring I would understand getting duplicates,
 even though I would think there should be no join in this call, since i am
 just checking a foreign key.  The kicker is that I always get row id 2 and
 never row id 1 when I make this call without the distinct call as well.
 If this were a cross-join, I should get multiple duplicates of all rows
 that meet the criteria, but I do not.

 I hope I explained this well enough, please feel free to contact me at my
 given email if you have any questions.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13073>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to