toasty_driver_integration_suite/scenarios/
has_one_optional_belongs_to.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::HasOne<Option<Profile>>,
16    }
17
18    #[derive(Debug, toasty::Model)]
19    struct Profile {
20        #[key]
21        #[auto]
22        id: ID,
23
24        #[unique]
25        user_id: Option<ID>,
26
27        #[belongs_to(key = user_id, references = id)]
28        user: toasty::BelongsTo<Option<User>>,
29
30        bio: String,
31    }
32
33    async fn setup(test: &mut Test) -> toasty::Db {
34        test.setup_db(models!(User, Profile)).await
35    }
36}