@jimka/typescript-ui / data / Model
Class: Model
Defined in: src/typescript/lib/data/Model.ts:22
A concrete, configurable model created at runtime from a field array. Use this class when you do not need a dedicated model subclass.
Extends
Constructors
new Model()
new Model(fields:
| (FieldOptions | Field)[]
| ModelOptions, primaryKey?: string): ModelDefined in: src/typescript/lib/data/Model.ts:32
Constructs a Model with the specified fields and an optional primary key.
Parameters
fields
An array of Field instances or FieldOptions objects that define the schema, or a ModelOptions bag.
(FieldOptions | Field)[] | ModelOptions
primaryKey?
string
Optional. The name of the field to use as the primary key. Ignored when the first argument is a ModelOptions bag.
Returns
Overrides
Properties
fields
readonly fields: (FieldOptions | Field)[];Defined in: src/typescript/lib/data/Model.ts:24
Overrides
Methods
createRecord()
createRecord(data: any[] | Record<string, any>): ModelRecordDefined in: src/typescript/lib/data/AbstractModel.ts:107
Creates a ModelRecord from a plain object or positional array, applying field mappings and defaults.
Parameters
data
Optional. The source data as a key/value object or a positional array. When an array is provided, values are assigned to fields ordered by their order property.
any[] | Record<string, any>
Returns
A new ModelRecord populated with mapped and defaulted field values.
Remarks
When data is an array, fields are sorted by their order value before being matched by position. Fields absent from data receive the value from field.getDefaultValue().
Inherited from
getField()
getField(name: string): undefined | FieldDefined in: src/typescript/lib/data/AbstractModel.ts:76
Returns the Field with the given name, or undefined if not found.
Parameters
name
string
The logical name of the field to look up.
Returns
undefined | Field
The matching Field, or undefined if no field with that name exists.
Inherited from
getFields()
getFields(): Field[]Defined in: src/typescript/lib/data/AbstractModel.ts:63
Returns all resolved Field instances for this model.
Returns
Field[]
An array of all Field instances defined on this model.
Inherited from
getPrimaryKeyField()
getPrimaryKeyField(): undefined | FieldDefined in: src/typescript/lib/data/AbstractModel.ts:50
Returns the Field designated as the primary key, or undefined if none is set.
Returns
undefined | Field
The primary key Field, or undefined if no primary key has been configured.
Inherited from
AbstractModel.getPrimaryKeyField
hasField()
hasField(name: string): booleanDefined in: src/typescript/lib/data/AbstractModel.ts:89
Returns true if the model contains a field with the given name.
Parameters
name
string
The logical name of the field to check.
Returns
boolean
True if a field with the given name exists, false otherwise.