Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Model

Hierarchy

  • Model

Index

Constructors

Properties

Methods

Constructors

Properties

_attributes: Attributes
_dirtyAttributes: Attributes
_exists: boolean
_malformedDocumentAttributes: Record<string, string[]>
_originalAttributes: Attributes
_proxy: Model
_relations: {}

Type declaration

_wasRecentlyCreated: boolean
id: string
__attributeGetters: Map<string, (() => unknown)> = ...
__attributeSetters: Map<string, ((value: unknown) => void)> = ...
classFields: string[] = []
collection: string
fields: FieldsDefinition<unknown>
modelName: string
primaryKey: string = 'id'
relations: string[] = []

Methods

  • afterSave(): Promise<void>
  • attributeValueChanged(originalValue: unknown, newValue: unknown): boolean
  • beforeSave(): Promise<void>
  • Creates a relation when this model references multiple instances of another model.

    Type Parameters

    Parameters

    • relatedClass: T

      Related model class.

    • Optional foreignKeyField: string

      Name of the foreign key field in the local model.

    • Optional localKeyField: string

      Name of the local key field in the related model. Defaults to the primary key name defined in the related model class.

    Returns BelongsToManyRelation<Model, Model, ModelConstructor<Model>>

  • Creates a relation when this model references one instance of another model.

    Type Parameters

    Parameters

    • relatedClass: T

      Related model class.

    • Optional foreignKeyField: string

      Name of the foreign key field in the local model.

    • Optional localKeyField: string

      Name of the local key field in the related model. Defaults to the primary key name defined in the related model class.

    Returns BelongsToOneRelation<Model, Model, ModelConstructor<Model>>

  • callAttributeGetter(field: string): unknown
  • callAttributeSetter(field: string, value: unknown): void
  • cleanDirty(): void
  • clone(options?: Partial<{ clean: boolean; clones: WeakMap<Model, Model>; constructors: WeakMap<typeof Model, typeof Model> | [typeof Model, typeof Model][] }>): Model
  • clone<T>(options?: Partial<{ clean: boolean; clones: WeakMap<Model, Model>; constructors: WeakMap<typeof Model, typeof Model> | [typeof Model, typeof Model][] }>): T
  • deleteModelsFromEngine(models: Model[]): Promise<void>
  • exists(): boolean
  • fixMalformedAttributes(): void
  • getAttribute<T>(field: string, includeUndefined?: boolean): T
  • Type Parameters

    • T = unknown

    Parameters

    • field: string
    • includeUndefined: boolean = false

    Returns T

  • getAttributeValue<T>(field: string, includeUndefined?: boolean): T
  • Type Parameters

    • T = unknown

    Parameters

    • field: string
    • includeUndefined: boolean = false

    Returns T

  • getAttributes(includeUndefined?: boolean): Attributes
  • getCascadeModels(): Promise<Model[]>
  • getDefaultCollection(): string
  • getEngine(): undefined | Engine
  • getFinalEngine(): undefined | Engine
  • getMalformedDocumentAttributes(): Record<string, string[]>
  • getOriginalAttribute<T>(field: string): T
  • getPrimaryKey(): any
  • getRelation<T>(relation: string): null | T
  • getRelationModel<T>(relation: string): null | T
  • getRelationModels<T>(relation: string): null | T[]
  • getSerializedPrimaryKey(): null | string
  • hasAttribute(field: string): boolean
  • hasAttributeGetter(field: string): boolean
  • hasAttributeSetter(field: string): boolean
  • Creates a relation when this model is referenced by multiple instances of another model.

    Type Parameters

    Parameters

    • relatedClass: T

      Related model class.

    • Optional foreignKeyField: string

      Name of the foreign key field in the related model.

    • Optional localKeyField: string

      Name of the local key field in the local model. Defaults to the primary key name defined in the local model class.

    Returns HasManyRelation<Model, Model, ModelConstructor<Model>>

  • Creates a relation when this model is referenced by one instance of another model.

    Type Parameters

    Parameters

    • relatedClass: T

      Related model class.

    • Optional foreignKeyField: string

      Name of the foreign key field in the related model.

    • Optional localKeyField: string

      Name of the local key field in the local model. Defaults to the primary key name defined in the local model class.

    Returns HasOneRelation<Model, Model, ModelConstructor<Model>>

  • hasRelation(relation: string): boolean
  • initialize(attributes: Attributes, exists: boolean): void
  • initializeAttributes(attributes: Attributes, exists: boolean): void
  • initializeProxy(): void
  • initializeRelations(): void
  • is(another: Model): boolean
  • isDirty(field?: string): boolean
  • isRelationLoaded(relation: string): boolean
  • loadEmptyRelations(): Promise<void>
  • loadRelation<T>(relation: string): Promise<T>
  • loadRelationIfUnloaded<T>(relation: string): Promise<T>
  • newInstance<T>(this: T, ...params: [attributes: Attributes, exists: boolean]): T
  • parseKey(key: string): any
  • performDelete(): Promise<void>
  • performMalformedAttributeFixes(): void
  • performSave(): Promise<void>
  • requireEngine<T>(): T
  • requireFinalEngine<T>(): T
  • requireRelation<T>(relation: string): T
  • reset(): void
  • resetEngineData(): void
  • serializeKey(key: any): string
  • setAttribute(field: string, value: unknown): void
  • setAttributeValue(field: string, value: unknown): void
  • setEngine(engine?: Engine): void
  • setExists(exists: boolean): void
  • setMalformedDocumentAttributes(malformedAttributes: Record<string, string[]>): void
  • setOriginalAttribute(field: string, value: unknown): void
  • setRelationModel(relation: string, model: null | Model): void
  • setRelationModels(relation: string, models: null | Model[]): void
  • Returns ModelConstructor<Model>

  • Parameters

    • property: "fields"

    Returns BootedFieldsDefinition<unknown>

  • Type Parameters

    • T extends "fields" | "prototype" | "collection" | "primaryKey" | "timestamps" | "modelName" | "classFields" | "relations" | "__attributeGetters" | "__attributeSetters" | "boot" | "create" | "createFromEngineDocument" | "createManyFromEngineDocuments" | "findOrFail" | "find" | "all" | "first" | "newInstance" | "on" | "instance" | "hasAutomaticTimestamp" | "hasAutomaticTimestamps" | "getEngine" | "getFinalEngine" | "requireEngine" | "requireFinalEngine" | "setEngine" | "withEngine" | "withoutTimestamps"

    Parameters

    • property: T

    Returns ModelConstructor<Model>[T]

  • syncDirty(): Promise<string>
  • touch(): void
  • unloadRelation(relation: string): void
  • unsetAttribute(field: string): void
  • wasRecentlyCreated(): boolean
  • withEngine(engine: Engine): Model
  • withEngine<T>(engine: Engine, operation: ((model: Model) => T)): T
  • withEngine<T>(engine: Engine, operation: ((model: Model) => Promise<T>)): Promise<T>
  • withoutTimestamps<T>(operation: (() => Promise<T>)): Promise<T>
  • Type Parameters

    • T

    Parameters

    • operation: (() => Promise<T>)
        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

  • getEngine(): undefined | Engine
  • getFinalEngine(): undefined | Engine
  • hasAutomaticTimestamps(): boolean
  • requireEngine<T>(): T
  • requireFinalEngine<T>(): T
  • setEngine(engine?: Engine): void
  • withEngine<T>(this: T, engine: Engine): T
  • withEngine<T>(engine: Engine, operation: (() => T)): T
  • withEngine<T>(engine: Engine, operation: (() => Promise<T>)): Promise<T>
  • withoutTimestamps<T>(operation: (() => Promise<T>)): Promise<T>
  • Type Parameters

    • T

    Parameters

    • operation: (() => Promise<T>)
        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

Generated using TypeDoc