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