#8892: ForeignKey relation not saved as expected
-------------------------------------+-------------------------------------
     Reporter:  julien               |                    Owner:
         Type:  Bug                  |  blacklwhite
    Component:  Database layer       |                   Status:  new
  (models, ORM)                      |                  Version:  1.0
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by altlist):

 I am a little confused why the original example isn't supported.

 {{{
 >>> a = ModelA(name='foo')
 >>> b = ModelB(name='bar')
 >>> b.a = a # Set relation *before* saving related object
 >>> a.save() # Save related object
 >>> a.pk
 123
 >>> b.a.pk
 123
 >>> b.save()
 >>> b = ModelB.objects.get(name='bar')
 >>> b.a
 <NoneType: None>
 }}}

 While I agree the docs suggests auto-increment keys can be determined
 upfront, the django model above shows a.pk is already known BEFORE I save
 b.  Hence I don't see why Django can't save object b correctly.

 Instead, I have to use the below suggested hack in the StackOverlow
 question.  Yet this seems cumbersome and unnecessary.

 {{{
 >>> b.a = b.a
 >>> b.save()
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/8892#comment:21>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.9a70d84d4e8baef767d0c17192497f66%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to