Skip to main content

toasty_driver_integration_suite/scenarios/
has_many_unique_title.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: ID,
24
25        #[belongs_to(key = user_id, references = id)]
26        user: toasty::Deferred<User>,
27
28        #[unique]
29        title: String,
30    }
31
32    async fn setup(test: &mut Test) -> toasty::Db {
33        test.setup_db(models!(User, Todo)).await
34    }
35}