v2 / vlib / v / tests / orm_joined_tables_select_test.v
38 lines · 33 sloc · 913 bytes · a80bc2331450fc28c900097f8afafe173f161d27
Raw
1// vtest build: present_sqlite3?
2import db.sqlite
3
4struct VieterDb {
5 conn sqlite.DB
6}
7
8pub struct GitRepoArch {
9pub:
10 id int @[primary; sql: serial]
11 repo_id int @[nonull]
12 // repo string
13 value string @[nonull]
14}
15
16pub struct GitRepo {
17pub mut:
18 id int @[optional; primary; sql: serial]
19 repo string @[nonull]
20 arch []GitRepoArch @[fkey: 'repo_id']
21}
22
23pub fn (db &VieterDb) get_git_repos() ![]GitRepo {
24 // NB: the query here, uses the `repo` field on GitRepo,
25 // while GitRepo is joined to GitRepoArch,
26 // which does *not* have a `repo` field.
27 // When this test was added, the checker used `GitRepoArch`
28 // to check for `repo`'s presence (which is wrong), because of
29 // a lingering c.cur_orm_ts state. The fix was to save/restore c.cur_orm_ts .
30 res := sql db.conn {
31 select from GitRepo where repo == 'something' order by id
32 }!
33 return res
34}
35
36fn test_compiles() {
37 assert true
38}
39