Class BaseModel

Base class for models

Constructors

Properties

id?: any
_adapter: AdapterBase

Indicates the adapter associated to this model

_associations: {
    [column: string]: any;
}
_connection: Connection<AdapterBase>

Indicates the connection associated to this model

_initialize_called: boolean = false
_integrities: {
    child?: typeof BaseModel;
    column: string;
    parent?: typeof BaseModel;
    type: string;
}[]
_intermediate_paths: any
_name: string
_object_column_classes?: {
    column: string;
    klass: any;
}[]
_property_decorators?: any[]
_schema: ModelSchemaInternal
archive: boolean = false

Archives deleted records in the archive table

description?: string
dirty_tracking: boolean = false

Tracks changes of a record if true

lean_query: boolean = false

Applies the lean option for all queries for this Model

query_record_id_as_string: boolean = false

Forces to return record id as string. It remains as number on the persisted record if the adapter uses number for record id.

table_name: string

Methods

  • Saves data to the database

    Parameters

    • options: {
          skip_log?: boolean;
          transaction?: Transaction;
          use_id_in_data?: boolean;
          validate?: boolean;
      } = {}
      • Optionalskip_log?: boolean
      • Optionaltransaction?: Transaction
      • Optionaluse_id_in_data?: boolean
      • Optionalvalidate?: boolean

    Returns Promise<BaseModel>

  • Parameters

    • data: any
    • model: any
    • column: string
    • property: ColumnPropertyInternal
    • allow_null: boolean = false

    Returns void

  • Set nested object null if all children are null

    Parameters

    • instance: any
    • selected_columns_raw: any
    • intermediates: any

    Returns void

  • Parameters

    • data: any
    • column: string
    • property: ColumnPropertyInternal
    • for_update: boolean = false

    Returns void

  • Adds a validator A validator must return false(boolean) or error message(string), or throw an Error exception if invalid

    Parameters

    • validator: any

    Returns void

  • Adds a belongs-to association

    Parameters

    • target_model_or_column: string | typeof BaseModel
    • Optionaloptions: AssociationBelongsToOptions

    Returns void

  • Creates a record. 'Model.build(data)' is the same as 'new Model(data)'

    Type Parameters

    Parameters

    • this: (new (data_arg?: any) => M)
        • new (data_arg?): M
        • Parameters

          • Optionaldata_arg: any

          Returns M

    • data: ModelValueObjectWithId<M>
    • options: {
          use_id_in_data: true;
      }
      • use_id_in_data: true

    Returns M

  • Type Parameters

    Parameters

    • this: (new (data_arg?: any) => M)
        • new (data_arg?): M
        • Parameters

          • Optionaldata_arg: any

          Returns M

    • Optionaldata: ModelValueObject<M>
    • Optionaloptions: {
          use_id_in_data?: boolean;
      }
      • Optionaluse_id_in_data?: boolean

    Returns M

  • Sets a connection of this model

    If this methods was not called explicitly, this model will use Connection.defaultConnection

    Parameters

    • connection: Connection<AdapterBase>
    • Optionalname: string

    Returns void

  • Adds a has-many association

    Parameters

    • target_model_or_column: string | typeof BaseModel
    • Optionaloptions: AssociationHasManyOptions

    Returns void

  • Adds a has-one association

    Parameters

    • target_model_or_column: string | typeof BaseModel
    • Optionaloptions: AssociationHasOneOptions

    Returns void

  • Adds an index to this model

    Parameters

    • columns: {
          [column: string]: 1 | -1;
      }
      • [column: string]: 1 | -1
    • options: {
          name?: string;
          unique?: boolean;
      } = {}
      • Optionalname?: string
      • Optionalunique?: boolean

    Returns void

  • Updates some fields of records that match conditions

    Parameters

    • updates: any
    • Optionalcondition: object
    • Optionaloptions: {
          transaction?: Transaction;
      }

    Returns Promise<number>