multiple inheritance issue
|Reported by:||pegler@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Django's support for multiple inheritance from several non-abstract models seems to almost be working. When both parent models have the same name for their PK, saving will update a related row instead of insert a new one.
Model: Pet - pk: id
Model: Mammal - pk: id
Model: Cat - inherits from Pet and Mammal, pk on the 2 foreign keys
Cat.save() will first insert a Pet row, since id isn't yet set. It will then set Cat.id to the new id values from Pet. It will then try to save Mammal, but since id has been set from Pet, it will try to update/insert a Mammal row (instead of always inserting).
The code at fault is here: https://code.djangoproject.com/browser/django/tags/releases/1.3.1/django/db/models/base.py#L492
I am not sure of the best solution for this, but perhaps not setting attributes that are also primary keys of other parent models.