Multiple OneToOne Models __really__ changed/Broke in Refactor
|Reported by:||Owned by:||nobody|
|Severity:||Keywords:||OneToOneField Refactor #7173|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
It now appears that only ONE one-to-one Sub table is allowed for Models ... this, well, i imagine will break lots of other folks things for example
# a simple 2 One-To-One tables models from django.db import models class BaseMoo(models.Model): name = models.CharField(max_length = 50) is_moo = models.BooleanField(default = True) class MooOne(models.Model): basemoo = models.OneToOneField(BaseMoo, primary_key = True) is_moo_one = models.BooleanField(default = True) class MooTwo(models.Model): basemoo = models.OneToOneField(BaseMoo, primary_key = True) is_moo_two = models.BooleanField(default = True)
and run a little run the test
b_moo = BaseMoo(name = "I Am Foo", is_moo = True) b_moo.save() MooOne(basemoo = b_moo, is_moo_one = True).save() MooTwo(basemoo = b_moo, is_moo_two = False).save() m_moo = BaseMoo.objects.get(name = "I Am Foo") try: print m_moo print repr(m_moo.mooone) print repr(m_moo.mootwo) print "\nMOO One", m_moo.mooone.is_moo_one, print "\nMOO Two", m_moo.mootwo.is_moo_two, except Exception, e: print "\nGADS!", e finally: m_moo.delete()
the scary output form that little test
BaseMoo object <MooOne: MooOne object> <MooOne: MooOne object> MOO One 1 MOO Two GADS! 'MooOne' object has no attribute 'is_moo_two'
As one can see the Attribute 'mootwo' is really pointing to 'mooone'.
It would be one thing if 'mootwo' as an attribute tossed an Attribute Error, but to point it at 'mooone' is really scary.
If this in fact the 'desired' effect now for OneToOnes, then really there needs to be some way (shown in the Documentation somewhere) to allow multiple OneToOnes to live on a given table ..