#17002: ManyToManyField through a model which extends some other model -------------------------------------+------------------------------------- Reporter: mitar | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: SVN (models, ORM) | Resolution: Severity: Normal | Triage Stage: Design Keywords: | decision needed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by sebastian):
* needs_better_patch: => 0 * needs_tests: => 0 * version: 1.3 => SVN * needs_docs: => 0 * type: New feature => Bug * stage: Unreviewed => Design decision needed Comment: Django expects the foreign key attributes to be present in the intermediary model given as the `through=` argument (and not some non- abstract parent) when constructing the related queries. On the other hand, model validation and table creation works even when the foreign key attributes are in the base class, or split over base and derived class as in e.g. {{{ class A(models.Model): pass class B(models.Model): a_s = models.ManyToManyField(A, through='Derived') class Base(models.Model): a = models.ForeignKey(A) class Derived(Base): b = models.ForeignKey(B) }}} The example validates just fine and even generates the appropriate database structure, but related queries fail during runtime, e.g. `B.objects.get(pk=1).a_s.all()` throws "DatabaseError: no such column: app_derived.a_id". Can you give an example where foreign keys in the base class of the intermediary model (as opposed to arbitrary attributes, or methods) are necessary or would be useful? In any case, I think the behavior here should be consistent. If the query cannot be created (because attributes are expected to be present in the derived table), then the validation of the model should not succeed. Or otherwise, the query should take attributes imported from base classes into account and insert the necessary joins. -- Ticket URL: <https://code.djangoproject.com/ticket/17002#comment:1> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.