Skip to main content

toasty_driver_integration_suite/scenarios/
user_two_children.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        posts: toasty::Deferred<Vec<Post>>,
14
15        #[has_many]
16        comments: toasty::Deferred<Vec<Comment>>,
17    }
18
19    #[derive(Debug, toasty::Model)]
20    struct Post {
21        #[key]
22        #[auto]
23        id: uuid::Uuid,
24
25        title: String,
26
27        #[index]
28        user_id: uuid::Uuid,
29
30        #[belongs_to(key = user_id, references = id)]
31        user: toasty::Deferred<User>,
32    }
33
34    #[derive(Debug, toasty::Model)]
35    struct Comment {
36        #[key]
37        #[auto]
38        id: uuid::Uuid,
39
40        text: String,
41
42        #[index]
43        user_id: uuid::Uuid,
44
45        #[belongs_to(key = user_id, references = id)]
46        user: toasty::Deferred<User>,
47    }
48
49    async fn setup(test: &mut Test) -> toasty::Db {
50        test.setup_db(models!(User, Post, Comment)).await
51    }
52}