#258 closed defect (invalid)
Cannot create many-many relationships within the same table
Description ¶
This model fails:
from django.core import meta # Create your models here. class Object(meta.Model): fields = ( meta.CharField('title', maxlength=50), ) class Relate(meta.Model): fields = ( meta.ForeignKey(Object, rel_name='parent'), meta.ForeignKey(Object, rel_name='child'), )
When you generate SQL for it, two columns with the name 'object_id' are placed in the 'relate' table. I was expecting columns with names 'parent_id' and 'child_id'.
Change History (2)
comment:1 by , 20 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 20 years ago
OK, this works, thanks :).
Any chance you could update the documentation to include it? At the moment, only ManyToManyField() shows the name option.
Note:
See TracTickets
for help on using tickets.
Your foreign keys need
name
attributes; it uses the name of the related-to object by default, so there's a clash (rel_name
is used for the names of the helper methods --get_parent
,get_child
, etc.)