Pre-alpha. No tagged release and no upgrade path between versions. Use for evaluation and development only, not production.
Core DevPre-alpha

How to extend a model with inherit=

Goal: add stored fields (and matching view xpath) to an existing ORM model from a dependent module without duplicating the base struct.

When to use

  • Your module depends on the module that owns the model (e.g. contacts depends on base for core.partner).
  • You need new columns on the same PostgreSQL table, not a separate model.

Steps

  1. Add an extension struct in your addon models/ package:

```go title="models/partner_extend.go" copy lines

package models

import "sumeru/core/sdk"

type PartnerContacts struct {

sdk.Model sumeru:"inherit=core.partner"

CustomerRank sdk.Integer sumeru:"string=Customer Rank,default=0"

}

```

Use inherit= with the technical model name of the target. Do not set model= on the same struct — the tags are mutually exclusive.

  1. Blank-import models from addon init.go if not already:

```go title="init.go" copy

import _ "sumeru/addons/contacts/models"

```

  1. Run make generate (or make build) so models/zmodels.go calls sdk.MustRegister for the extension struct.
  1. Update schema by installing or updating your module:

```bash shell copy

go run ./cmd/sumeru -- -c sumeru.conf -u contacts --stop-after-init

```

SyncRegistrySchemaForModule includes models extended by the module and runs additive DDL for new columns.

  1. Expose fields in the UI with view xpath inherit (see View inherit xpath).

Go + XML together (contacts example)

models/partner_extend.go
package models import "sumeru/core/sdk" type PartnerContacts struct {	sdk.Model `sumeru:"inherit=core.partner"` 	CustomerRank sdk.Integer `sumeru:"string=Customer Rank,default=0"`}
views/core_partner_form_inherit_views.xml
<record id="view_core_partner_form_contacts_inherit" model="sys.view">    <field name="inherit_id" ref="contacts.view_core_partner_form"/>    <field name="arch" type="xml">        <xpath expr="//field[@name='phone']" position="after">            <field name="customer_rank" string="Customer Rank"/>        </xpath>    </field></record>

Rules and limits

  • The base model must register first (enforce with manifest.depends and correct addon import order).
  • Duplicate field names on the same model cause a startup panic with a clear error.
  • Go method override on models is not supported in v1 — use RegisterObjectAction or event.Subscribe for behavior.
  • Delegation inherit (parent table per record) is out of scope for this mechanism.

Live example

See also