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: docs/06-concepts/06-database/02-models.md
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -53,3 +53,45 @@ fields:
53
53
```
54
54
55
55
For a complete guide on how to work with relations see the [relation section](relations/one-to-one).
56
+
57
+
## Change ID type
58
+
59
+
Changing the type of the `id` field allows you to customize the identifier type for your database tables. This is done by declaring the `id` field on table models with one of the supported types. If the field is omitted, the id field will still be created with type `int`, as have always been.
60
+
61
+
The following types are supported for the `id` field:
| **int** | serial | serial (optional) | - | 64-bit serial integer. |
66
+
| **UuidValue** | random | random | random | UUID v4 value. |
67
+
68
+
### Declaring a Custom ID Type
69
+
70
+
To declare a custom type for the `id` field in a table model file, use the following syntax:
71
+
72
+
```yaml
73
+
class: UuidIdTable
74
+
table: uuid_id_table
75
+
fields:
76
+
id: UuidValue?, defaultPersist=random
77
+
```
78
+
79
+
```yaml
80
+
class: IntIdTable
81
+
table: int_id_table
82
+
fields:
83
+
id: int?, defaultPersist=serial // The default keyword for 'int' is optional.
84
+
```
85
+
86
+
#### Default Uuid model value
87
+
88
+
For UUIDs, it is possible to configure the `defaultModel` value. This will ensure that UUIDs are generated as soon as the object is created, rather than when it is persisted to the database. This is useful for creating objects offline or using them before they are sent to the server.
89
+
90
+
```yaml
91
+
class: UuidIdTable
92
+
table: uuid_id_table
93
+
fields:
94
+
id: UuidValue, defaultModel=random
95
+
```
96
+
97
+
When using `defaultModel=random`, the UUID will be generated when the object is created. Since an id is always assigned the `id` field can be non-nullable.
|**all**| Enables all available experimental features. |
32
+
|**inheritance**| Allows using the `extends` keyword in your model files to create class hierarchies. |
34
33
35
34
## Inheritance
36
35
@@ -101,48 +100,6 @@ class ChildClass extends ParentClass {
101
100
All files in a sealed hierarchy need to be located in the same directory.
102
101
:::
103
102
104
-
## Change ID type
105
-
106
-
Changing the type of the `id` field allows you to customize the identifier type for your database tables. This is done by declaring the `id` field on table models with one of the supported types. If the field is omitted, the id field will still be created with type `int`, as have always been.
107
-
108
-
The following types are supported for the `id` field:
| **int** | serial | serial (optional) | - | 64-bit serial integer. |
113
-
| **UuidValue** | random | random | random | UUID v4 value. |
114
-
115
-
### Declaring a Custom ID Type
116
-
117
-
To declare a custom type for the `id` field in a table model file, use the following syntax:
118
-
119
-
```yaml
120
-
class: UuidIdTable
121
-
table: uuid_id_table
122
-
fields:
123
-
id: UuidValue?, defaultPersist=random
124
-
```
125
-
126
-
```yaml
127
-
class: IntIdTable
128
-
table: int_id_table
129
-
fields:
130
-
id: int?, defaultPersist=serial // The default keyword for 'int' is optional.
131
-
```
132
-
133
-
#### Default Uuid model value
134
-
135
-
For UUIDs, it is possible to configure the `defaultModel` value. This will ensure that UUIDs are generated as soon as the object is created, rather than when it is persisted to the database. This is useful for creating objects offline or using them before they are sent to the server.
136
-
137
-
```yaml
138
-
class: UuidIdTable
139
-
table: uuid_id_table
140
-
fields:
141
-
id: UuidValue, defaultModel=random
142
-
```
143
-
144
-
When using `defaultModel=random`, the UUID will be generated when the object is created. Since an id is always assigned the `id` field can be non-nullable.
145
-
146
103
## Exception monitoring
147
104
148
105
Serverpod allows you to monitor exceptions in a central and flexible way by using the new diagnostic event handlers.
0 commit comments