Hi gang,
I've been hunting down some bugs with serialization of multi-table
inheritance, and I need a sanity check on something that I want to
check in.
Specifically, I think I've found a discrepancy in the way
OneToOneFields are used. Consider these examples:
class Place(models.Model):
name = models.CharField(max_length=10)
class Restaurant(Place):
capacity = models.IntegerField()
class Stadium(Place):
parent = models.OneToOneField(Place, parent_link=True)
capacity = models.IntegerField()
When you sync the Restaurant model, Restaurant gets an implicit
OneToOne field added to manage the inheritance. This OneToOne field is
given a default name of "place_ptr", but is _NOT_ set to be a primary
key. This also means that Restaurant has ID field that is independent
of the place_ptr field.
Supplier has explicitly provided its parent field, using the
parent_link=True option. However, when we sync the Supplier models,
Supplier.parent is converted into a primary key. This happens on line
100 of django.db.models.base.py, during the processing of the base
classes in the meta model construction. Since the O2O field is
primary, Supplier doesn't have an independent ID field.
Now, here's where I need a sanity check:
To my understanding Stadium and Restaurant _should_ be identical,
except for the naming of the parent link.
To that end, my understanding is that the error lies in the way the
Stadium model is incorrect - that is, the OneToOneField for
multi-table inheritance is not _required_ to be the primary key for
the child model (although it could be, if you manually set it to be).
If I disable line 100 (where the primary key setting is forced), none
of the system tests fail. This change make sense to me logically, but
I want to make sure -applying this fix will be a backwards
incompatible change. Any table created with the old scheme will need
to be recreated.
Can anyone think of a reason why primary_key is currently being forced
on manually specified parent links? Alternatively, is it the handling
of Restaurant that is incorrect, and the implicit OneToOneField should
be a primary key?
Yours,
Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---