orm: fix orm insert issue if table missing [Issue : #20017] (#20580)

This commit is contained in:
GGRei 2024-02-10 03:52:09 +01:00 committed by GitHub
parent 16574df99b
commit 2d0ed2c1d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 0 deletions

View file

@ -348,6 +348,54 @@ fn test_orm_insert_with_multiple_child_elements() {
assert parent.notes[2].text == 'Third note'
}
fn test_orm_insert_with_child_element_and_no_table() {
mut db := sqlite.connect(':memory:')!
sql db {
create table Parent
}!
new_parent := Parent{
name: 'test'
children: [
Child{
name: 'Lisa'
},
]
}
sql db {
insert new_parent into Parent
} or { assert true }
sql db {
create table Child
}!
sql db {
insert new_parent into Parent
} or { assert false }
new_parent_two := Parent{
name: 'retest'
children: [
Child{
name: 'Sophia'
},
]
}
sql db {
insert new_parent_two into Parent
} or { assert false }
p_table := sql db {
select from Parent
}!
assert p_table[2].children[0].name == 'Sophia'
}
@[table: 'customers']
struct Customer {
id i64 @[primary; sql: serial]