Skip to main content

toasty_driver_integration_suite/scenarios/
has_many_nullable_fk.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        #[has_many]
13        todos: toasty::Deferred<Vec<Todo>>,
14    }
15
16    #[derive(Debug, toasty::Model)]
17    struct Todo {
18        #[key]
19        #[auto]
20        id: ID,
21
22        #[index]
23        user_id: Option<ID>,
24
25        #[belongs_to(key = user_id, references = id)]
26        user: toasty::Deferred<Option<User>>,
27
28        title: String,
29    }
30
31    async fn setup(test: &mut Test) -> toasty::Db {
32        test.setup_db(models!(User, Todo)).await
33    }
34}