#34549: Extra select query when parent model consists of primary key only
-------------------------------------+-------------------------------------
     Reporter:  Akash Kumar Sen      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Akash Kumar Sen):

 **Case 2 :** The parent model consists of other fields along with primary
 key

 The  {{{models.py}}}

 {{{
 from django.db import models

 class ParentModel(models.Model):
     id = models.BigIntegerField(primary_key=True)
     name = models.CharField(max_length=10)
     value = models.IntegerField()

 class ChildModel(ParentModel):
     pass
 }}}

 The testcase


 {{{
 class Ticke30382TestCase(TestCase):
     def test_force_insert_save(self):
         with self.assertNumQueries(0):
             ChildModel(id=1, name="Akash",
 value=5).save(force_insert=True)
 }}}

 Queries Captured


 {{{
 1. UPDATE "force_insert_update_parentmodel" SET "name" = 'Akash', "value"
 = 5 WHERE "force_insert_update_parentmodel"."id" = 1
 2. INSERT INTO "force_insert_update_parentmodel" ("id", "name", "value")
 VALUES (1, 'Akash', 5)
 3. INSERT INTO "force_insert_update_childmodel" ("parentmodel_ptr_id")
 VALUES (1)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34549#comment:2>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070187fe2a3934-0529edeb-ac19-4baf-ab19-7f054456dacc-000000%40eu-central-1.amazonses.com.

Reply via email to