#9553: Save of ForeignKeys's model doesn't cause update of _id field
---------------------------------------------------+------------------------
Reporter: oldium | Owner: nobody
Status: closed | Milestone:
Component: Database layer (models, ORM) | Version: 1.0
Resolution: invalid | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by kmtracey):
* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0
Comment:
Right, inner does not have a primary key value until you call save() on
it. So you cannot correctly specify it as the target of outer's key
before then. Your code should be:
{{{
#!python
inner = Inner(field="test")
inner.save()
outer = Outer(inner=inner, other_field="other test")
outer.save()
}}}
I'm pretty sure this is spelled out somewhere in the docs though I can't
find it at the moment. The fact that save() is what creates the object's
pk is noted here:
http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs
#auto-incrementing-primary-keys
--
Ticket URL: <http://code.djangoproject.com/ticket/9553#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 [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
-~----------~----~----~----~------~----~------~--~---