Commit ab3eea7
committed
Set up the groundwork for multi-table joins
This solves the fundamental problem of needing
`SelectableExpression<Join<Left, Right>> for column` to work when we
don't know where the table concretely appears, just that it appears
somewhere. With this commit, the logic is now that a column can be
selected from any join where its table appears within the join exactly
once. This disallows `users.inner_join(posts.inner_join(users))`, which
we don't want to allow as it would require the second instance of
`users` to be aliased.
This does require that there is an `impl ContainsTable<left> for right`
for every two tables that would appear. Right now I'm just brute-forcing
these when the association between the two tables is defined. For
multi-table joins to work when two of the tables in the join do not have
an association, this will require a manual impl. We'll probably provide
something like `enable_multi_table_joins!(users, comments)` or similar.
This *may* go away eventually with specialization, if projections on
default associated types are eventually allowed in the fully monomorphic
case.
It should be noted that this commit does not enable multi-table joins on
itself. `Join` still does not implement `JoinDsl`, and tables do not
implement `JoinTo<Join<Mid, Right>>`. The code required to enable that
is pretty minimal, but I don't want to flip the switch just yet, as
we're actually generating invalid SQL at the moment and that needs to be
resolved.
However, with this change, all of the limitations that prevent
multi-table joins at the type level are eliminated.1 parent 201c8cd commit ab3eea7
3 files changed
Lines changed: 62 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 29 | + | |
| 30 | + | |
43 | 31 | | |
44 | 32 | | |
45 | 33 | | |
46 | | - | |
47 | | - | |
| 34 | + | |
| 35 | + | |
48 | 36 | | |
49 | | - | |
50 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
51 | 40 | | |
52 | 41 | | |
53 | 42 | | |
54 | | - | |
55 | | - | |
| 43 | + | |
| 44 | + | |
56 | 45 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 46 | + | |
| 47 | + | |
64 | 48 | | |
65 | 49 | | |
66 | 50 | | |
67 | 51 | | |
68 | 52 | | |
69 | | - | |
| 53 | + | |
70 | 54 | | |
71 | 55 | | |
72 | 56 | | |
| |||
339 | 323 | | |
340 | 324 | | |
341 | 325 | | |
| 326 | + | |
342 | 327 | | |
343 | 328 | | |
344 | 329 | | |
| |||
418 | 403 | | |
419 | 404 | | |
420 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
421 | 410 | | |
422 | 411 | | |
423 | 412 | | |
| |||
426 | 415 | | |
427 | 416 | | |
428 | 417 | | |
429 | | - | |
| 418 | + | |
| 419 | + | |
430 | 420 | | |
431 | 421 | | |
432 | 422 | | |
| |||
534 | 524 | | |
535 | 525 | | |
536 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
537 | 530 | | |
538 | 531 | | |
539 | 532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | 136 | | |
143 | 137 | | |
144 | 138 | | |
| |||
180 | 174 | | |
181 | 175 | | |
182 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments