@@ -9,21 +9,31 @@ using Mocking
9
9
Random. seed! (42 )
10
10
11
11
mutable struct Role <: Wasabi.Model
12
- id:: Union{Nothing, Int }
12
+ id:: Union{Nothing, Integer }
13
13
name:: String
14
+ user_id:: Integer
15
+
16
+ Role (name:: String , user_id:: Integer ) = new (nothing , name, user_id)
17
+ end
18
+
19
+ mutable struct UserProfile <: Wasabi.Model
20
+ id:: Union{Nothing, Int}
14
21
user_id:: Int
22
+ bio:: Union{String,Nothing}
15
23
16
- Role (name:: String , user_id:: Int ) = new (nothing , name, user_id)
24
+ UserProfile (user_id:: Integer , bio:: Union{String,Nothing} ) = new (nothing , user_id, bio)
25
+ UserProfile (id:: Integer , user_id:: Integer , bio:: Union{String,Nothing} ) = new (id, user_id, bio)
17
26
end
18
27
19
28
mutable struct User <: Wasabi.Model
20
- id:: Union{Nothing, Int }
29
+ id:: Union{Nothing, Integer }
21
30
name:: String
22
31
created_at:: DateTime
23
32
roles:: Vector{Role}
33
+ profile:: Union{Nothing, UserProfile}
24
34
25
- User (name:: String , created_at:: DateTime , roles:: Vector{Role} = Role[]) = new (nothing , name, created_at, roles)
26
- User (id:: Number , name:: String , created_at:: DateTime , roles:: Vector{Role} = Role[]) = new (id, name, created_at, roles)
35
+ User (name:: String , created_at:: DateTime , roles:: Vector{Role} = Role[], profile :: Union{Nothing, UserProfile} = nothing ) = new (nothing , name, created_at, roles, profile )
36
+ User (id:: Integer , name:: String , created_at:: DateTime , roles:: Vector{Role} = Role[]) = new (id, name, created_at, roles, nothing )
27
37
end
28
38
29
39
# struct UserProfile <: Wasabi.Model
41
51
Wasabi. primary_key (m:: Type{User} ) = Wasabi. PrimaryKeyConstraint (Symbol[:id ])
42
52
Wasabi. primary_key (m:: Type{Role} ) = Wasabi. PrimaryKeyConstraint (Symbol[:id ])
43
53
Wasabi. foreign_keys (m:: Type{Role} ) = [Wasabi. ForeignKeyConstraint (Symbol[:user_id ], :user , Symbol[:id ])]
44
- Wasabi. exclude_fields (m:: Type{User} ) = [:roles ]
54
+ Wasabi. exclude_fields (m:: Type{User} ) = [:roles , :profile ]
45
55
46
56
# Wasabi.primary_key(m::Type{UserProfile}) = Wasabi.PrimaryKeyConstraint(Symbol[:id])
47
57
0 commit comments