Class BaseModel

Base class for models

Constructors

Properties

_attributes?: any
_intermediates?: any
_is_persisted?: any
_prev_attributes?: any
id?: any
_adapter: AdapterBase

Indicates the adapter associated to this model

_associations: {
    [column: string]: any;
}

Type declaration

  • [column: string]: any
_callbacks_map?: {
    create: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[];
    destroy: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[];
    find: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[];
    initialize: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[];
    save: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[];
    update: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[];
    validate: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[];
}

Type declaration

  • create: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[]
  • destroy: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[]
  • find: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[]
  • initialize: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[]
  • save: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[]
  • update: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[]
  • validate: undefined | {
        method: ModelCallbackMethod;
        type: ModelCallbackType;
    }[]
_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;
}[]

Type declaration

  • Optional child?: typeof BaseModel
  • column: string
  • Optional parent?: typeof BaseModel
  • type: string
_intermediate_paths: any
_name: string
_object_column_classes?: {
    column: string;
    klass: any;
}[]

Type declaration

  • column: string
  • klass: any
_property_decorators?: any[]
_schema: ModelSchemaInternal
_validators: any[]
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

  • Parameters

    • options: {
          skip_log?: boolean;
          transaction?: Transaction;
          use_id_in_data?: boolean;
      }
      • Optional skip_log?: boolean
      • Optional transaction?: Transaction
      • Optional use_id_in_data?: boolean

    Returns Promise<{}>

  • Saves data to the database

    Parameters

    • options: {
          skip_log?: boolean;
          transaction?: Transaction;
          use_id_in_data?: boolean;
          validate?: boolean;
      } = {}
      • Optional skip_log?: boolean
      • Optional transaction?: Transaction
      • Optional use_id_in_data?: boolean
      • Optional validate?: 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 callback

    Parameters

    • type: ModelCallbackType
    • name: ModelCallbackName
    • method: ModelCallbackMethod

    Returns number

  • 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
    • Optional options: AssociationBelongsToOptions

    Returns void

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

    Type Parameters

    Parameters

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

          • Optional data_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?) => M)
        • new (data_arg?): M
        • Parameters

          • Optional data_arg: any

          Returns M

    • Optional data: ModelValueObject<M>
    • Optional options: {
          use_id_in_data?: boolean;
      }
      • Optional use_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>
    • Optional name: string

    Returns void

  • Creates a record and saves it to the database 'Model.create(data)' is the same as 'Model.build(data).save()'

    Type Parameters

    Parameters

    Returns Promise<M>

  • Type Parameters

    Parameters

    • this: (new (data_arg?) => M) & typeof BaseModel
    • Optional data: ModelValueObject<M>
    • Optional options: {
          skip_log?: boolean;
          transaction?: Transaction;
          use_id_in_data?: boolean;
      }
      • Optional skip_log?: boolean
      • Optional transaction?: Transaction
      • Optional use_id_in_data?: boolean

    Returns Promise<M>

  • Adds a has-many association

    Parameters

    • target_model_or_column: string | typeof BaseModel
    • Optional options: AssociationHasManyOptions

    Returns void

  • Adds a has-one association

    Parameters

    • target_model_or_column: string | typeof BaseModel
    • Optional options: AssociationHasOneOptions

    Returns void

  • Adds an index to this model

    Parameters

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

    Returns void

  • Updates some fields of records that match conditions

    Parameters

    • updates: any
    • Optional condition: object
    • Optional options: {
          transaction?: Transaction;
      }

    Returns Promise<number>

Generated using TypeDoc