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