Skip to main content

toasty_driver_integration_suite/scenarios/
user_todo_step.rs

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