@absolunet/ioc2.1.0

View on GitHub

Model

Database model that implements ORM features to transact with Knex with an Active Record Pattern (ARP) approach.

Constructor

(abstract) new Model(app, engine)

Source:
Model constructor.
Parameters:
Name Type Description
app foundation.Application The current application instance.
engine * The engine that exposes the base model.
Returns:
An engine model factory, wrapped by a proxy.
Type
function

Extends

Members

(static) dependencies :Array.<string>

Source:
Class dependencies: ['app', 'engine'].

defaults :object

Source:
Default values.

timestamps :boolean

Source:
Flag that indicates if the model has timestamp columns.

key :string

Source:
Primary key column name.

keyType :string

Source:
Primary key column type.

table :string

Source:
Table name.

definition :object

Source:
Get model definition for the underlying model system.

app :foundation.Application

Source:
Application accessor.

Methods

boot()

Source:
Boot the model on initialization.

getDefaults()

Source:
Get default values.
Returns:
The default values.
Type
object

getHasTimestamps()

Source:
Get if the model has timestamp columns.
Returns:
Indicates that the model uses timestamps.
Type
boolean

getIdAttribute()

Source:
Get primary key column name.
Returns:
The primary column name.
Type
string

getIdType()

Source:
Get primary key column type.
Returns:
The primary column type.
Type
string

getProcessors()

Source:
Get a list of all processors.
Returns:
The processors list for each columns.
Type
object.<string, function()>

getTableName()

Source:
Get table name.
Returns:
The table name.
Type
string

getForward()

Source:
Get ORM model for forward calls.
Returns:
The ORM model instance.
Type
*

getRelationBuilders()

Source:
Get relation builders that maps relation names with their query builder.
Returns:
The mapped relations with their builder.
Type
object.<string, function()>

(async) create(attributes)

Source:
Create a new record in the database.
Parameters:
Name Type Description
attributes object The attributes to create the model with.
Returns:
The newly created model instance.
Type
Promise.<database.Model>