diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-04 07:21:14 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-04 07:21:14 +0000 |
| commit | f9c8eeb31133d3bf55ae167168fcb2d90ce4d12a (patch) | |
| tree | 87c6e755f228f21670dc7b99c78fa6075237f3ae /tests/regressiontests | |
| parent | dfd7a6c7811c49371838f593387ae6db7bb7ef30 (diff) | |
Fixed #10406 -- Fixed some problems with model inheritance and pk fields.
Manually specifying both a OneToOneField(parent_link=True) and separate a
primary key field was causing invalid SQL to be generated. Thanks to Ramiro
Morales for some analysis on this one.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9971 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/model_inheritance_regress/models.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/regressiontests/model_inheritance_regress/models.py b/tests/regressiontests/model_inheritance_regress/models.py index d2fa4cbf15..a1ee6a2d86 100644 --- a/tests/regressiontests/model_inheritance_regress/models.py +++ b/tests/regressiontests/model_inheritance_regress/models.py @@ -43,6 +43,16 @@ class ParkingLot(Place): def __unicode__(self): return u"%s the parking lot" % self.name +class ParkingLot2(Place): + # In lieu of any other connector, an existing OneToOneField will be + # promoted to the primary key. + parent = models.OneToOneField(Place) + +class ParkingLot3(Place): + # The parent_link connector need not be the pk on the model. + primary_key = models.AutoField(primary_key=True) + parent = models.OneToOneField(Place, parent_link=True) + class Supplier(models.Model): restaurant = models.ForeignKey(Restaurant) @@ -293,5 +303,20 @@ True >>> DerivedM.objects.all() [<DerivedM: PK = 44, base_name = b1, derived_name = d1>] +# Regression tests for #10406 + +# If there's a one-to-one link between a child model and the parent and no +# explicit pk declared, we can use the one-to-one link as the pk on the child. +# The ParkingLot2 model shows this behaviour. +>>> ParkingLot2._meta.pk.name +"parent" + +# However, the connector from child to parent need not be the pk on the child +# at all. +>>> ParkingLot3._meta.pk.name +"primary_key" +>>> ParkingLot3._meta.get_ancestor_link(Place).name # the child->parent link +"parent" + """} |
