toasty_driver_integration_suite/scenarios/
user_account_subscription.rs1use crate::prelude::*;
2
3scenario! {
4 #![id(ID)]
12
13 #[derive(Debug, toasty::Model)]
14 struct User {
15 #[key]
16 #[auto]
17 id: ID,
18
19 name: String,
20
21 #[has_one]
22 account: toasty::Deferred<Option<Account>>,
23
24 #[has_one(via = account.subscription)]
26 subscription: toasty::Deferred<Option<Subscription>>,
27 }
28
29 #[derive(Debug, toasty::Model)]
30 struct Account {
31 #[key]
32 #[auto]
33 id: ID,
34
35 #[unique]
36 user_id: Option<ID>,
37
38 #[belongs_to(key = user_id, references = id)]
39 user: toasty::Deferred<Option<User>>,
40
41 #[has_one]
42 subscription: toasty::Deferred<Option<Subscription>>,
43 }
44
45 #[derive(Debug, toasty::Model)]
46 struct Subscription {
47 #[key]
48 #[auto]
49 id: ID,
50
51 #[unique]
52 account_id: Option<ID>,
53
54 #[belongs_to(key = account_id, references = id)]
55 account: toasty::Deferred<Option<Account>>,
56
57 plan: String,
58 }
59
60 async fn setup(test: &mut Test) -> toasty::Db {
61 test.setup_db(models!(User, Account, Subscription)).await
62 }
63}