#11199: Select_related added to the query set will produce empty result
---------------------------------------------------+------------------------
          Reporter:  milosu                        |         Owner:  nobody
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  1.0   
        Resolution:                                |      Keywords:        
             Stage:  Unreviewed                    |     Has_patch:  0     
        Needs_docs:  0                             |   Needs_tests:  0     
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by Alex):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Old description:

> You have a model like:
>
> class Driver:
>     name = models.CharField(max_length=100)
>
> class Car:
>     name = models.CharField(max_length=100)
>     driver = models.ForeignKey(Driver)
>
> Inside the database mangle the fkey from car to driver as nullable and
> insert some records into car table without the reference to the driver
> table.
>
> Than just try:
> Car.objects.filter(name = 'something').select_related()
>
> and you will get empty queryset when evaluated.
>
> I guess this is a correct ORM behaviour when using inner joins etc.
>
> Could this be documented somewhere? It was quite mysterious for me to
> make an observation like this and to find the problem (missing null=True
> model declaration)..

New description:

 You have a model like:
 {{{
 class Driver:
     name = models.CharField(max_length=100)

 class Car:
     name = models.CharField(max_length=100)
     driver = models.ForeignKey(Driver)
 }}}
 Inside the database mangle the fkey from car to driver as nullable and
 insert some records into car table without the reference to the driver
 table.

 Than just try:
 {{{
 Car.objects.filter(name = 'something').select_related()
 }}}
 and you will get empty queryset when evaluated.

 I guess this is a correct ORM behaviour when using inner joins etc.

 Could this be documented somewhere? It was quite mysterious for me to make
 an observation like this and to find the problem (missing null=True model
 declaration)..

Comment:

 Please use preview.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11199#comment:1>
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-updates@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