#13343: Wrong behavior of ManyToMany relationship while using 'trough' in
ManyToManyField  and 'db_column' and 'to_field' properties in intermediate
model
---------------------------------------------------+------------------------
          Reporter:  twil                          |         Owner:  nobody  
            Status:  new                           |     Milestone:  1.2     
         Component:  Database layer (models, ORM)  |       Version:  1.2-beta
        Resolution:                                |      Keywords:          
             Stage:  Accepted                      |     Has_patch:  0       
        Needs_docs:  0                             |   Needs_tests:  0       
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by twil):

 New, stripped down and abstract version of models:
 {{{
 #!python
 from django.db import models

 class Item(models.Model):
     unique_field = models.IntegerField(unique = True)
     title = models.CharField(max_length = 10)

 class Group(models.Model):
     title = models.CharField(max_length = 10)
     members = models.ManyToManyField('Item', through = 'GroupItem')

 class GroupItem(models.Model):
     item = models.ForeignKey('Item', to_field = 'unique_field')
     group = models.ForeignKey('Group')
     title = models.CharField(max_length = 10)
 }}}

 and shell test sequence of commands:
 {{{
 #!text
 Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
 [GCC 4.3.2] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 (InteractiveConsole)
 >>> from testm2m.m2m.models import *
 >>> item1 = Item.objects.create(unique_field = 100, title = 'Item')
 >>> group1 = Group.objects.create(title = 'Group')
 >>> membership = GroupItem.objects.create(item = item1, group = group1,
 title = 'Membership')
 >>> membership.save()
 >>> group1.members.all()
 []
 >>> from django.db import connection
 >>> connection.queries
 [{'time': '0.002', 'sql': u'INSERT INTO "m2m_item" ("unique_field",
 "title") VALUES (100, Item)'}, {'time': '0.001', 'sql': u'INSERT INTO
 "m2m_group" ("title") VALUES (Group)'}, {'time': '0.001', 'sql': u'INSERT
 INTO "m2m_groupitem" ("item_id", "group_id", "title") VALUES (100, 1,
 Membership)'}, {'time': '0.000', 'sql': u'SELECT (1) AS "a",
 "m2m_groupitem"."id", "m2m_groupitem"."item_id",
 "m2m_groupitem"."group_id", "m2m_groupitem"."title" FROM "m2m_groupitem"
 WHERE "m2m_groupitem"."id" = 1  LIMIT 1'}, {'time': '0.001', 'sql':
 u'UPDATE "m2m_groupitem" SET "item_id" = 100, "group_id" = 1, "title" =
 Membership WHERE "m2m_groupitem"."id" = 1 '}, {'time': '0.000', 'sql':
 u'SELECT "m2m_item"."id", "m2m_item"."unique_field", "m2m_item"."title"
 FROM "m2m_item" INNER JOIN "m2m_groupitem" ON ("m2m_item"."id" =
 "m2m_groupitem"."item_id") WHERE "m2m_groupitem"."group_id" = 1  LIMIT
 21'}]
 }}}

 PS: I've tried to make patch but couldn't find right place in django code
 :( I'll try tomorrow again.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13343#comment:2>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to