toasty_driver_integration_suite/scenarios/
user_profile_and_todos.rs1use 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_many]
18 todos: toasty::Deferred<Vec<Todo>>,
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 Todo {
38 #[key]
39 #[auto]
40 id: ID,
41
42 title: String,
43
44 #[index]
45 user_id: ID,
46
47 #[belongs_to(key = user_id, references = id)]
48 user: toasty::Deferred<User>,
49 }
50
51 async fn setup(test: &mut Test) -> toasty::Db {
52 test.setup_db(models!(User, Profile, Todo)).await
53 }
54}