Entity Basics
What names are automatically generated when I name an Entity 'product'?
What names are automatically generated when I name an Entity 'product'?
Entity ID is enforced as CamelCase, and various names are auto-generated based on it.Input: ProductAuto-generated names:Generated type/class names:Conversion rules:
-
Entity ID (id)
Product(same as input)- Validation:
/^[A-Z][a-zA-Z0-9]*$/(CamelCase required)
-
Table name (table)
products(auto-pluralized)- Customizable (direct input in Sonamu UI)
-
File/directory name (
names.fs)product(lowercase + dash)- Used for: directory names, file names
-
Module name (
names.module)Product(same as input)- Used for: class names, type names
-
ID →
table:inflection.underscore(inflection.pluralize(id))Product→productsOrderItem→order_items
-
ID →
fs:inflection.dasherize(inflection.underscore(id)).toLowerCase()Product→productOrderItem→order-item
- Entity ID must start with uppercase (CamelCase)
- Table name is auto-generated but customizable
What are the conditions for auto-generating migrations when Entity is modified?
What are the conditions for auto-generating migrations when Entity is modified?
When Entity is modified, migrations are not auto-generated. You must manually Generate in the Sonamu UI’s DB Migration tab.Migration generation targets (shown in Prepared Migration Codes):Props changes:
- Prop add/delete
- Prop type change (
string→numeric, etc.) StringProplength change (length)nullablechangedbDefaultchangeprecision,scalechange whenNumberProphasnumberType: "numeric"
- BelongsToOne add/delete (FK column create/delete)
- OneToOne add/delete (when
hasJoinColumn: true) - ManyToMany add/delete (join table create/delete)
- onUpdate, onDelete changes
- Index add/delete
- unique, index, fulltext type changes
- Index column changes
- Table name change
- Subset add/modify/delete
- Enum labels change
- Virtual prop add/modify/delete
- HasMany relation add/modify (FK is on the other side)
- Title, Description changes
- Migration files are not auto-generated after Entity modification
- Check DB Migration tab → Prepared Migration Codes
- Manual generation required by clicking Generate button
What order are files created when I create a new Entity in Sonamu UI?
What order are files created when I create a new Entity in Sonamu UI?
1. Entity JSON file created
{entity}.entity.json- Location:
api/src/application/{entity}/{entity}.entity.json
{entity}.types.ts- Location:
api/src/application/{entity}/{entity}.types.ts
sonamu.generated.sso.tssonamu.generated.ts- Location:
api/src/application/
user.types.ts→web/src/services/user/user.types.tssonamu.generated.ts→web/src/services/sonamu.generated.ts
sonamu.lock updated- Stores checksums of newly created files
- Migration files are not auto-generated
- Separate Generate click required in DB Migration tab
model,model_test,vieware generated separately in Scaffolding tab
Entity Properties
How do I define Entity enums?
How do I define Entity enums?
Define in the
enums object with enum ID as key and value-label pairs as object:- Key (
normal,admin): Actual value stored in DB - Value (Normal, Admin): Label displayed in UI
- Enum ID (
UserRole): Used as TypeScript type name
- DB values in English (for internationalization and migration ease)
- UI labels in user’s language
What is a virtual field and when do I use it?
What is a virtual field and when do I use it?
A calculated field that is included in query results but has no DB column.How to create (Sonamu UI):Implementation (Enhancer approach):Main use cases:
- Entity detail → Click Add a prop
- Type: Select
virtual - Name: Enter field name (e.g.,
company_stats) - Check
Nullable: true - CustomType ID: Select type (e.g.,
CompanyStatsType)
{entity}.types.ts):- Relation data aggregation (employee count, comment count)
- Complex statistics objects (department stats, company dashboard)
- User-specific status (like status, permission info)
- Nested JSON structures (metadata, config objects)
.omit({ virtual_field: true })required inSaveParams- Implement calculation logic in Enhancer
- Consider performance for complex calculations
Entity Relations
How do I define relations between Entities?
How do I define relations between Entities?
Define with
relation type fields:OneToOne: 1:1 relation- Specify FK owner with
hasJoinColumn
- Defined in Entity that has the FK
- virtual relation (FK is on the other side)
- Requires
joinTable
onUpdate, onDelete options in the Entity that has the FK.How do I define a BelongsToOne relation?
How do I define a BelongsToOne relation?
Represents an N:1 (Many-to-One) relation.How to configure (Sonamu UI):
- Entity detail → Click Add a prop
- Type: Select
relation - Relation Type: Select
BelongsToOne - Name: Relation field name (e.g.,
department) - With: Entity ID to connect (e.g.,
Department) - Nullable:
truefor optional relations - ON UPDATE/ON DELETE: Select
CASCADE,SET NULL,RESTRICT,NO ACTION, etc.
- Foreign key column auto-created (e.g.,
department_id) - Type includes
department?: Department
Model Classes
How do I create an API route without an Entity connected to DB?
How do I create an API route without an Entity connected to DB?
There are two ways to create independent APIs without an Entity.Method 1: Add @api decorator to existing ModelMethod 2: Use FrameFrame is a class for creating independent APIs without an Entity.Frame characteristics:
- Extends
BaseFrameClass - Provides
getDB(),getUpsertBuilder()methods - No Entity, Subset, Model methods
- Filename:
{name}.frame.ts
- Related to existing Entity: Add method to that Model
- Completely independent: Create Frame class
How should I refactor when Model class becomes too large?
How should I refactor when Model class becomes too large?
When Model class grows, you can separate independent logic into Frame classes.Problem: user.model.ts becomes largeImprovement: Separate into user-util.frame.tsSeparation criteria:
- Directly related to User Entity: Keep in
user.model.ts - Utility-type features: Separate to
user-util.frame.ts - Completely independent: Create separate Frame class
What does the EntityManager class do?
What does the EntityManager class do?
A singleton class that centrally manages all Entities.Main features:
- Entity lookup
- Auto-generate names (table, fs, module)
- Schema validation
- Subset lookup
- Subset field expansion
- Model classes
- API decorators
- Syncer
- Migration generator
How do I validate Entity schemas?
How do I validate Entity schemas?
Sonamu UI:Syncer:
- Real-time error display when editing Entity
- Auto-validates and outputs errors when running
pnpm dev
- Required fields exist
- Type validity
- Subset references
- Enum validity