Setting pk should set the related fields also in the base chain.
|Reported by:||akaariai||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.2|
|Severity:||Keywords:||Inheritance, parent_link, OneToOneField|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Consider two models:
class A(models.Model): pass class B(A): a = models.OneToOneField(A, parent_link=True, primary_key=True)
creating an b instance and setting its pk should also set the a.id:
>>> b = B(pk=1) >>> b.pk 1 >>> b.a_id 1 >>> b.id 1
At the moment we will get:
>>> b.id is None True
It would be even better if setting b.id would also set b.a_id, but that is harder to do, and maybe it isn't that important.