Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orm: fix cgen inserting wrong array index (#19324)
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import db.sqlite | ||
|
||
struct Person { | ||
id int [primary; sql: serial] | ||
age int | ||
brothers []Brother [fkey: 'person_id'] | ||
sisters []Sister [fkey: 'person_id'] | ||
field_after_fkeys string | ||
} | ||
|
||
struct Brother { | ||
id int [primary; sql: serial] | ||
person_id int | ||
name string | ||
} | ||
|
||
struct Sister { | ||
id int [primary; sql: serial] | ||
person_id int | ||
name string | ||
} | ||
|
||
fn test_field_after_fkeys() { | ||
db := sqlite.connect(':memory:') or { panic(err) } | ||
|
||
sql db { | ||
create table Brother | ||
create table Sister | ||
create table Person | ||
}! | ||
|
||
person := Person{ | ||
age: 21 | ||
brothers: [Brother{ | ||
name: 'aaa' | ||
}, Brother{ | ||
name: 'bbb' | ||
}] | ||
sisters: [Sister{ | ||
name: 'ccc' | ||
}, Sister{ | ||
name: 'ddd' | ||
}] | ||
field_after_fkeys: 'eee' | ||
} | ||
|
||
sql db { | ||
insert person into Person | ||
}! | ||
|
||
persons := sql db { | ||
select from Person | ||
}! | ||
|
||
assert persons[0].age == 21 | ||
assert persons[0].field_after_fkeys == 'eee' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters