#26667: Invalid query for OneToOneField if 'to_field'  specified and
primary_key=True
-------------------------------------+-------------------------------------
     Reporter:  kwist                |      Owner:  nobody
         Type:  Uncategorized        |     Status:  new
    Component:  Database layer       |    Version:  1.9
  (models, ORM)                      |   Keywords:  OneToOneField to_field
     Severity:  Normal               |  primary_key
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 Given the following models:
 {{{
 #!python
 class Model1(models.Model):
     str_id = models.CharField(max_length=12, unique=True)


 class Model2(models.Model):
     model1 = models.OneToOneField(Model1, to_field='str_id',
 primary_key=True)
 }}}

 In Django 1.9 query:
 {{{
 #!python
 Model2.objects.filter(model1=instance_model1)
 }}}
 always returns an empty list, though in Django 1.8 works

 Django 1.9 query
 {{{
 #!python
 In [4]: print Model2.objects.filter(model1=model1).query
 SELECT "app_model2"."model1_id" FROM "app_model2" WHERE
 "app_model2"."model1_id" = 1
 }}}

 Django 1.8 query
 {{{
 #!python
 In [4]: print Model2.objects.filter(model1=model1).query
 SELECT `app_model2`.`model1_id` FROM `app_model2` WHERE
 `app_model2`.`model1_id` = 1234567890ax
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26667>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.d2850cae781360038f5b81c30fc96108%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to