mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
parent
16574df99b
commit
2d0ed2c1d6
2 changed files with 52 additions and 0 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue