toasty_driver_integration_suite/scenarios/
user_org_project_todo.rs1use crate::prelude::*;
2
3scenario! {
4 #[derive(Debug, toasty::Model)]
15 struct User {
16 #[key]
17 #[auto]
18 id: uuid::Uuid,
19
20 name: String,
21
22 #[has_many]
23 organizations: toasty::Deferred<Vec<Organization>>,
24
25 #[has_many(via = organizations.projects.todos)]
27 todos: toasty::Deferred<Vec<Todo>>,
28
29 #[has_many(via = organizations.todos)]
32 nested_todos: toasty::Deferred<Vec<Todo>>,
33
34 #[has_many(via = organizations.todos.title)]
38 nested_todo_titles: toasty::Deferred<Vec<String>>,
39 }
40
41 #[derive(Debug, toasty::Model)]
42 struct Organization {
43 #[key]
44 #[auto]
45 id: uuid::Uuid,
46
47 name: String,
48
49 #[index]
50 user_id: uuid::Uuid,
51
52 #[belongs_to(key = user_id, references = id)]
53 user: toasty::Deferred<User>,
54
55 #[has_many]
56 projects: toasty::Deferred<Vec<Project>>,
57
58 #[has_many(via = projects.todos)]
61 todos: toasty::Deferred<Vec<Todo>>,
62 }
63
64 #[derive(Debug, toasty::Model)]
65 struct Project {
66 #[key]
67 #[auto]
68 id: uuid::Uuid,
69
70 name: String,
71
72 #[index]
73 organization_id: uuid::Uuid,
74
75 #[belongs_to(key = organization_id, references = id)]
76 organization: toasty::Deferred<Organization>,
77
78 #[has_many]
79 todos: toasty::Deferred<Vec<Todo>>,
80 }
81
82 #[derive(Debug, toasty::Model)]
83 struct Todo {
84 #[key]
85 #[auto]
86 id: uuid::Uuid,
87
88 title: String,
89
90 #[index]
91 project_id: uuid::Uuid,
92
93 #[belongs_to(key = project_id, references = id)]
94 project: toasty::Deferred<Project>,
95 }
96
97 async fn setup(test: &mut Test) -> toasty::Db {
98 test.setup_db(models!(User, Organization, Project, Todo)).await
99 }
100}