toasty_driver_integration_suite/scenarios/
user_comment_article.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 comments: toasty::Deferred<Vec<Comment>>,
16
17 #[has_many(via = comments.article)]
19 commented_articles: toasty::Deferred<Vec<Article>>,
20
21 #[has_many(via = comments.article.title)]
23 commented_article_titles: toasty::Deferred<Vec<String>>,
24
25 #[has_many(via = comments.body)]
29 comment_bodies: toasty::Deferred<Vec<String>>,
30 }
31
32 #[derive(Debug, toasty::Model)]
33 struct Article {
34 #[key]
35 #[auto]
36 id: ID,
37
38 title: String,
39
40 #[has_many]
41 comments: toasty::Deferred<Vec<Comment>>,
42 }
43
44 #[derive(Debug, toasty::Model)]
45 struct Comment {
46 #[key]
47 #[auto]
48 id: ID,
49
50 body: String,
51
52 #[index]
53 user_id: ID,
54
55 #[belongs_to(key = user_id, references = id)]
56 user: toasty::Deferred<User>,
57
58 #[index]
59 article_id: ID,
60
61 #[belongs_to(key = article_id, references = id)]
62 article: toasty::Deferred<Article>,
63 }
64
65 async fn setup(test: &mut Test) -> toasty::Db {
66 test.setup_db(models!(User, Article, Comment)).await
67 }
68}