#37115: Add support for Generic Relations / Table-Valued Expressions in the ORM
-------------------------------------+-------------------------------------
Reporter: Pravin | Owner: Pravin
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Table-Valued | Triage Stage: Accepted
expressions, Set-returning |
functions, SRF, generate_series, |
Postgres, Orm |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
As mentioned in a few locations already (forum, discord, github) I think
that in order to even consider adding this feature we must add support for
a generic `CompositeField`. We don't have a ticket for that but Lilly did
some exploration work for it [
https://github.com/django/django/pull/17279
here] that predated adding support for `CompositePrimaryKey`.
The reason is simple, we need a way to adequately represent the
`output_field` of these `Expression` to remove the hack we have right now
on `sql.Query.output_field`. Once we have that the problem of supporting
table-like expressions becomes much simpler as we can make members of
`sql.Query.alias_map` (which hosts table-like references) subclasses of
`Expression` instead of opaque `BaseTable` and `Join` datastructures and
augment them with compilation directives such as where they should
''live'' (inlined in the `FROM` clause, as a `CTE`) and how they should be
combined (e.g. `LATERAL JOIN`)
From there things like
{{{#!python
Author.objects.alias(
book=Books.objects.values("title", "number_of_pages")
)
}}}
become much easier to implement as any expression that has
`.output_field.is_composite` can be treated a candidate for `alias_map`
inclusion.
--
Ticket URL: <
https://code.djangoproject.com/ticket/37115#comment:4>