Skip to main content

toasty_driver_integration_suite/scenarios/
user_todo_step.rs

1use crate::prelude::*;
2
3scenario! {
4    #![id(ID)]
5
6    #[derive(Debug, toasty::Model)]
7    struct User {
8        #[key]
9        #[auto]
10        id: ID,
11
12        name: String,
13
14        #[has_many]
15        todos: toasty::Deferred<Vec<Todo>>,
16    }
17
18    #[derive(Debug, toasty::Model)]
19    struct Todo {
20        #[key]
21        #[auto]
22        id: ID,
23
24        title: String,
25
26        #[index]
27        user_id: ID,
28
29        #[belongs_to(key = user_id, references = id)]
30        user: toasty::Deferred<User>,
31
32        #[has_many]
33        steps: toasty::Deferred<Vec<Step>>,
34    }
35
36    #[derive(Debug, toasty::Model)]
37    struct Step {
38        #[key]
39        #[auto]
40        id: ID,
41
42        description: String,
43
44        #[index]
45        todo_id: ID,
46
47        #[belongs_to(key = todo_id, references = id)]
48        todo: toasty::Deferred<Todo>,
49    }
50
51    async fn setup(test: &mut Test) -> toasty::Db {
52        test.setup_db(models!(User, Todo, Step)).await
53    }
54}