Skip to main content

toasty_driver_integration_suite/scenarios/
user_profile_settings.rs

1use 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_one]
15        profile: toasty::Deferred<Option<Profile>>,
16
17        #[has_one]
18        settings: toasty::Deferred<Option<Settings>>,
19    }
20
21    #[derive(Debug, toasty::Model)]
22    struct Profile {
23        #[key]
24        #[auto]
25        id: ID,
26
27        bio: String,
28
29        #[unique]
30        user_id: Option<ID>,
31
32        #[belongs_to(key = user_id, references = id)]
33        user: toasty::Deferred<Option<User>>,
34    }
35
36    #[derive(Debug, toasty::Model)]
37    struct Settings {
38        #[key]
39        #[auto]
40        id: ID,
41
42        theme: String,
43
44        #[unique]
45        user_id: Option<ID>,
46
47        #[belongs_to(key = user_id, references = id)]
48        user: toasty::Deferred<Option<User>>,
49    }
50
51    async fn setup(test: &mut Test) -> toasty::Db {
52        test.setup_db(models!(User, Profile, Settings)).await
53    }
54}