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