toasty_driver_integration_suite/scenarios/
has_many_multi_relation.rs1use 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 #[index]
23 user_id: uuid::Uuid,
24
25 #[belongs_to(key = user_id, references = id)]
26 user: toasty::Deferred<User>,
27
28 #[index]
29 category_id: uuid::Uuid,
30
31 #[belongs_to(key = category_id, references = id)]
32 category: toasty::Deferred<Category>,
33
34 title: String,
35 }
36
37 #[derive(Debug, toasty::Model)]
38 struct Category {
39 #[key]
40 #[auto]
41 id: uuid::Uuid,
42
43 name: String,
44
45 #[has_many]
46 todos: toasty::Deferred<Vec<Todo>>,
47 }
48
49 async fn setup(test: &mut Test) -> toasty::Db {
50 test.setup_db(models!(User, Todo, Category)).await
51 }
52}