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