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