toasty_driver_integration_suite/tests/
infra_missing_registrations.rs

1use crate::prelude::*;
2
3/// Registering only the Parent model should auto-discover the Child model
4/// through the BelongsTo relation.
5#[driver_test(id(ID))]
6pub async fn missing_registration_belongs_to(t: &mut Test) -> Result<()> {
7    #[derive(Debug, toasty::Model)]
8    struct Parent {
9        #[key]
10        #[auto]
11        id: ID,
12
13        child_id: ID,
14        #[belongs_to(key = child_id, references = id)]
15        child: toasty::BelongsTo<Child>,
16    }
17
18    #[derive(Debug, toasty::Model)]
19    struct Child {
20        #[key]
21        #[auto]
22        id: ID,
23    }
24
25    // Auto-discovery should find Child through the BelongsTo relation.
26    t.try_setup_db(models!(Parent)).await?;
27
28    Ok(())
29}
30
31/// Registering only the Parent model should auto-discover the Child model
32/// through the HasOne relation.
33#[driver_test(id(ID))]
34pub async fn missing_registration_has_one(t: &mut Test) -> Result<()> {
35    #[derive(Debug, toasty::Model)]
36    struct Parent {
37        #[key]
38        #[auto]
39        id: ID,
40
41        #[has_one]
42        child: toasty::HasOne<Child>,
43    }
44
45    #[derive(Debug, toasty::Model)]
46    struct Child {
47        #[key]
48        #[auto]
49        id: ID,
50
51        #[index]
52        parent_id: ID,
53        #[belongs_to(key = parent_id, references = id)]
54        parent: toasty::BelongsTo<Parent>,
55    }
56
57    // Auto-discovery should find Child through the HasOne relation.
58    t.try_setup_db(models!(Parent)).await?;
59
60    Ok(())
61}
62
63/// Registering only the Parent model should auto-discover the Child model
64/// through the HasMany relation.
65#[driver_test(id(ID))]
66pub async fn missing_registration_has_many(t: &mut Test) -> Result<()> {
67    #[derive(Debug, toasty::Model)]
68    struct Parent {
69        #[key]
70        #[auto]
71        id: ID,
72
73        #[has_many]
74        children: toasty::HasMany<Child>,
75    }
76
77    #[derive(Debug, toasty::Model)]
78    struct Child {
79        #[key]
80        #[auto]
81        id: ID,
82
83        #[index]
84        parent_id: ID,
85        #[belongs_to(key = parent_id, references = id)]
86        parent: toasty::BelongsTo<Parent>,
87    }
88
89    // Auto-discovery should find Child through the HasMany relation.
90    t.try_setup_db(models!(Parent)).await?;
91
92    Ok(())
93}
94
95/// Registering only the Parent model should auto-discover the Detail embedded
96/// model through the embedded field.
97#[driver_test(id(ID))]
98pub async fn missing_registration_embedded(t: &mut Test) -> Result<()> {
99    #[derive(Debug, toasty::Model)]
100    struct Parent {
101        #[key]
102        #[auto]
103        id: ID,
104
105        detail: Detail,
106    }
107
108    #[derive(Debug, toasty::Embed)]
109    struct Detail {
110        x: i32,
111    }
112
113    // Auto-discovery should find Detail through the embedded field.
114    t.try_setup_db(models!(Parent)).await?;
115
116    Ok(())
117}