@@ -53,18 +53,26 @@ fn (mut g Gen) sql_insert_expr(node ast.SqlExpr) {
5353 g.sql_table_name = g.table.sym (node.table_expr.typ).name
5454
5555 // orm_insert needs an SqlStmtLine, build it from SqlExpr (most nodes are the same)
56- hack_stmt_line := ast.SqlStmtLine{
57- object_var: node.inserted_var
58- fields: node.fields
59- table_expr: node.table_expr
60- // sub_structs: node.sub_structs
61- }
56+ hack_stmt_line := g.build_sql_stmt_line_from_sql_expr (node)
6257 g.write_orm_insert (hack_stmt_line, table_name, connection_var_name, result_var_name,
6358 node.or_expr, table_attrs)
6459
6560 g.write2 (left, 'orm__Connection_name_table[${connection_var_name }._typ]._method_last_id(${connection_var_name }._object)' )
6661}
6762
63+ fn (mut g Gen) build_sql_stmt_line_from_sql_expr (node ast.SqlExpr) ast.SqlStmtLine {
64+ mut sub_structs := map [int ]ast.SqlStmtLine{}
65+ for typ, sub in node.sub_structs {
66+ sub_structs[typ] = g.build_sql_stmt_line_from_sql_expr (sub)
67+ }
68+ return ast.SqlStmtLine{
69+ object_var: node.inserted_var
70+ fields: node.fields
71+ table_expr: node.table_expr
72+ sub_structs: sub_structs
73+ }
74+ }
75+
6876// sql_stmt writes C code that calls ORM functions for
6977// performing various database operations such as creating and dropping tables,
7078// as well as inserting and updating objects.
0 commit comments