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