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