You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guidance/guarded-struct.livemd
+84-1Lines changed: 84 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -842,6 +842,14 @@ defmodule ExternalAuthCallModuleStruct do
842
842
end
843
843
```
844
844
845
+
```elixir
846
+
ExternalAuthCallModuleStruct.builder(%{
847
+
name:"Mishka",
848
+
auth_path: %{action:"add"},
849
+
auth_path1: [%{action:"add"}]
850
+
})
851
+
```
852
+
845
853
## List of structs
846
854
847
855
As was discussed in the earlier available choices. In the `field` macro that is used to call **another module**, as well as in the `sub_field` macro, you have the ability to retrieve a list of structs rather than a single struct.
@@ -958,9 +966,19 @@ end
958
966
959
967
> **Note**: When changing a record in the database, for example, you might need to make sure that a particular piece of data does not get overwritten by an automatic piece of data if one already exists. To find a solution to this issue, you will need to invoke the `builder` function in the following manner.
You can select this alternative if you require any data that was delivered in another key to be incorporated into the key that you are looking for. If the key is present, the data associated with it will be copied; however, if the key is not there, the data in and of itself will be retained.
@@ -1057,6 +1099,14 @@ defmodule FromCoreKeyStruct do
When dealing with a structure that is heavily nested, it is occasionally necessary to establish the permitted range of values for a set of parameters based on the input provided by a parent.
@@ -1086,6 +1136,17 @@ defmodule AllowedParentDomain do
**Please see the `domain` core key, for example:**
1090
1151
1091
1152
<!-- livebook:{"force_markdown":true} -->
@@ -1162,6 +1223,20 @@ defmodule AllowedParentCustomDomain do
1162
1223
end
1163
1224
```
1164
1225
1226
+
```elixir
1227
+
AllowedParentCustomDomain.builder(%{
1228
+
username:"mishka",
1229
+
auth: %{action:"ok"}
1230
+
})
1231
+
```
1232
+
1233
+
```elixir
1234
+
AllowedParentCustomDomain.builder(%{
1235
+
username:"mishka",
1236
+
auth: %{action:"error"}
1237
+
})
1238
+
```
1239
+
1165
1240
**Note**: if you want to use `custom` inside `derive` validation, you should do like this:
1166
1241
1167
1242
```elixir
@@ -1179,6 +1254,14 @@ end
1179
1254
1180
1255
**Note**: You can see when you use it inside a derive, the GuardedStruct calculates the you module `alias`.
1181
1256
1257
+
```elixir
1258
+
CustomValidationDerive.builder(%{status:"ok"})
1259
+
```
1260
+
1261
+
```elixir
1262
+
CustomValidationDerive.builder(%{status:"error"})
1263
+
```
1264
+
1182
1265
## Conditional fields
1183
1266
1184
1267
One of the unique capabilities of this macro is the ability to define conditions and differentiate between the various kinds of `fields`. Assume that you want the `social` field to be able to take both a value `string` and a `map` where `address` and `provider` are included in the `map`.
0 commit comments