#29551: My use-case of QuerySet.extra(): Join two models without explicit relation --------------------------------+-------------------------------------- Reporter: Bowser | Owner: nobody Type: Uncategorized | Status: closed Component: Uncategorized | Version: 2.0 Severity: Normal | Resolution: invalid Keywords: QuerySet.extra | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 --------------------------------+-------------------------------------- Changes (by Simon Charette):
* status: new => closed * resolution: => invalid Comment: Hey Bowser, I think the best approach here would be to define a `django.db.models.related.ForeignObject` on your model by making sure to define appropriate `from_fields` and `to_fields`. Such objects will behave just like `ForeignKey`s with regards to ORM interactions (`filter`, `annotate`, `values`, ...) but aren't backed by a implicit concrete column. Under the hood `ForeignKey` is a subclass of `ForeignKey` that creates a concrete a column to use it as `from_fields` and defaults `to_fields` to the referenced model's primary key. For example on your `Inbox` model. {{{#!python class Inbox(models.Model): ... sender_email = models.EmailField(db_column='SenderEmail') customer = ForeignObject(Customer, models.CASCADE, from_fields=['sender_email'], to_fields=['email']) class Meta: managed = False ... }}} I'll close this ticket as invalid for now but feel free to re-open it if the provided alternative to your usage of `extra()` isn't appropriate. -- Ticket URL: <https://code.djangoproject.com/ticket/29551#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 unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.ea046e055b81e9b16eee2e6748097b7d%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.