Skip to main content

toasty_driver_integration_suite/scenarios/
has_many_same_target.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(pair = author)]
13        authored_articles: toasty::Deferred<Vec<Article>>,
14
15        #[has_many(pair = reviewer)]
16        reviewed_articles: toasty::Deferred<Vec<Article>>,
17    }
18
19    #[derive(Debug, toasty::Model)]
20    struct Article {
21        #[key]
22        #[auto]
23        id: uuid::Uuid,
24
25        title: String,
26
27        #[index]
28        author_id: uuid::Uuid,
29
30        #[index]
31        reviewer_id: uuid::Uuid,
32
33        #[belongs_to(key = author_id, references = id)]
34        author: toasty::Deferred<User>,
35
36        #[belongs_to(key = reviewer_id, references = id)]
37        reviewer: toasty::Deferred<User>,
38    }
39
40    async fn setup(test: &mut Test) -> toasty::Db {
41        test.setup_db(models!(User, Article)).await
42    }
43}