1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#[macro_export]
macro_rules! HasMany {
(
($child_table_name:ident, foreign_key = $foreign_key_name:ident)
$($rest:tt)*
) => {
HasMany! {
(
child_table = $child_table_name::table,
foreign_key = $child_table_name::$foreign_key_name,
)
$($rest)*
}
};
(
($($args:tt)*)
#[table_name($table_name:ident)]
$($rest:tt)*
) => {
HasMany! {
(
parent_table_name = $table_name,
$($args)*
)
$($rest)*
}
};
(
$args:tt
$(#[$ignore:meta])*
$(pub)* struct $($body:tt)*
) => {
HasMany! {
$args
$($body)*
}
};
(
(
parent_table_name = $parent_table_name:ident,
child_table = $child_table:path,
foreign_key = $foreign_key:path,
),
fields = [$({
field_name: $field_name:ident,
column_name: $column_name:ident,
field_ty: $field_ty:ty,
field_kind: $field_kind:ident,
$($rest:tt)*
})+],
) => {
joinable_inner! {
left_table_ty = $parent_table_name::table,
right_table_ty = $child_table,
right_table_expr = $child_table,
foreign_key = $foreign_key,
primary_key_ty = <$parent_table_name::table as $crate::query_source::Table>::PrimaryKey,
primary_key_expr = $crate::Table::primary_key(&$parent_table_name::table),
}
$(select_column_inner!(
$parent_table_name::table,
$child_table,
$parent_table_name::$column_name,
);)+
select_column_inner!(
$parent_table_name::table,
$child_table,
$parent_table_name::star,
);
};
(
$args:tt
$struct_name:ident
$body:tt $(;)*
) => {
__diesel_parse_struct_body! {
$args,
callback = HasMany,
body = $body,
}
};
}