Skip to content

Commit 9f91064

Browse files
authored
orm: fix sub_structs (fix #25104) (#25105)
1 parent 54f7c36 commit 9f91064

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎vlib/v/gen/c/orm.v‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,15 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
360360
final_field_typ := g.table.final_type(field.typ)
361361
sym := g.table.sym(final_field_typ)
362362
if sym.kind == .struct && sym.name != 'time.Time' {
363-
subs << unsafe { node.sub_structs[int(final_field_typ)] }
364-
unwrapped_c_typ := g.styp(final_field_typ.clear_flag(.option))
365-
subs_unwrapped_c_typ << if final_field_typ.has_flag(.option) {
366-
unwrapped_c_typ
367-
} else {
368-
''
363+
if final_field_typ in node.sub_structs {
364+
subs << unsafe { node.sub_structs[int(final_field_typ)] }
365+
366+
unwrapped_c_typ := g.styp(final_field_typ.clear_flag(.option))
367+
subs_unwrapped_c_typ << if final_field_typ.has_flag(.option) {
368+
unwrapped_c_typ
369+
} else {
370+
''
371+
}
369372
}
370373
} else if sym.kind == .array {
371374
// Handle foreign keys
@@ -377,7 +380,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
377380
if final_field_typ.has_flag(.option) {
378381
opt_fields << arrs.len
379382
}
380-
if node.sub_structs.len > 0 {
383+
if final_field_typ in node.sub_structs {
381384
arrs << unsafe { node.sub_structs[int(final_field_typ)] }
382385
}
383386
field_names << field.name

0 commit comments

Comments
 (0)