Skip to main content

toasty_driver_integration_suite/scenarios/
composite_has_many_belongs_to.rs

1use crate::prelude::*;
2
3scenario! {
4    #[derive(Debug, toasty::Model)]
5    struct User {
6        #[key]
7        #[auto]
8        id: uuid::Uuid,
9
10        #[index]
11        name: String,
12
13        #[has_many]
14        todos: toasty::Deferred<Vec<Todo>>,
15    }
16
17    #[derive(Debug, toasty::Model)]
18    #[key(partition = user_id, local = id)]
19    struct Todo {
20        #[auto]
21        id: uuid::Uuid,
22
23        user_id: uuid::Uuid,
24
25        #[belongs_to(key = user_id, references = id)]
26        user: toasty::Deferred<User>,
27
28        #[index]
29        title: String,
30    }
31
32    async fn setup(test: &mut Test) -> toasty::Db {
33        test.setup_db(models!(User, Todo)).await
34    }
35}