Models & fields
sdk.Model tags, field markers, relations, and how runtime records are maps.
sdk.Model and generate
Prefer sumeru/core/sdk over importing sumeru/core/orm directly. Embed sdk.Model with a sumeru:"model=…" tag. After adding a struct, run make generate so models/zmodels.go registers it. Cross-package FKs (wizards) use sdk.Many2One[sdk.Any] plus comodel=.
package models import ( "sumeru/core/sdk") // MyModule is the primary record for My Module.type MyModule struct { sdk.Model `sumeru:"model=my.module"` Name sdk.String `sumeru:"required,index,string=Name"` Description sdk.Text `sumeru:"string=Description"` Active sdk.Boolean `sumeru:"default=true,string=Active"` Sequence sdk.Integer `sumeru:"default=10,string=Sequence"`}
Field types
| Constant | Wire value | Use |
|---|---|---|
Char | char | Short string |
Text | text | Long text |
Integer | integer | Whole number |
Float | float | Floating point |
Numeric | numeric | Exact decimal (money) |
Boolean | boolean | True/false |
Date | date | Calendar date |
DateTime | datetime | Timestamp |
Selection | selection | Fixed key/label pairs |
Many2One | many2one | FK to another model |
Many2Many | many2many | Relation table |
One2Many | one2many | Inverse of Many2One |
Json | json | JSON document |
Computed fields
Register derived values with orm.RegisterCompute in core or addon init(). Computed fields are filled on read via ApplyComputes. This is not runtime model inheritance or automatic write-time recomputation — declare deps explicitly and keep logic in Go.
orm.RegisterCompute("sale.order", "amount_display", []string{"amount_total"}, func(ctx context.Context, rec map[string]interface{}) (interface{}, error) { return fmt.Sprintf("%.2f", rec["amount_total"]), nil })
FieldDefinition fields
| Field | Purpose |
|---|---|
Name | Column / field name |
Type | One of the FieldType constants |
Required | NOT NULL / required in UI |
Relation | Target model for M2O / M2M / O2M |
RelationTable | Join table name for M2M |
Column1 | This model's FK column in the M2M table |
Column2 | Target model's FK column in the M2M table |
String | Human label |
DefaultVal | Default value |
Selection | [][]string options: {{"key","Label"}, ...} |
Unique | Unique constraint |
Index | Create a database index |
Runtime records are maps
ORM reads and writes use map[string]interface{} keyed by field name (plus id). Schema sync follows generated model metadata from struct tags.
Compile and run
make generatego run . -- -c sumeru.conf -i my_module --stop-after-initmake run
Schema sync. Install/update syncs columns from FieldDefinition. Review migrations on shared databases. Sumeru is pre-alpha.
What not to do
- Do not skip
make generateafter adding a model struct, and do not callRegisterModelin addon code. - Do not invent FieldType strings outside the constants above.
- Do not put business logic that must survive restarts only in struct methods the ORM never calls.
Next step
Bind screens in Views & menus.