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::HasMany<Comment>,
16
17 #[has_many(via = comments.article)]
19 commented_articles: toasty::HasMany<Article>,
20 }
21
22 #[derive(Debug, toasty::Model)]
23 struct Article {
24 #[key]
25 #[auto]
26 id: ID,
27
28 title: String,
29
30 #[has_many]
31 comments: toasty::HasMany<Comment>,
32 }
33
34 #[derive(Debug, toasty::Model)]
35 struct Comment {
36 #[key]
37 #[auto]
38 id: ID,
39
40 body: String,
41
42 #[index]
43 user_id: ID,
44
45 #[belongs_to(key = user_id, references = id)]
46 user: toasty::BelongsTo<User>,
47
48 #[index]
49 article_id: ID,
50
51 #[belongs_to(key = article_id, references = id)]
52 article: toasty::BelongsTo<Article>,
53 }
54
55 async fn setup(test: &mut Test) -> toasty::Db {
56 test.setup_db(models!(User, Article, Comment)).await
57 }
58}