Protected
Readonly
busProtected
Optional
dirtyDatabase fields that should be run on the next save, even if the fields are not mapped to members on the model.
Optional
firstThe user's first name.
Optional
lastThe user's last name.
Protected
Readonly
loggingProtected
Optional
originalThe original row fetched from the database.
The hashed and salted password of the user.
Cache of relation instances by property accessor.
This is used by the @Relation()
decorator to cache Relation instances.
Protected
scopesProtected
subscribersLocal listeners subscribed to events on this bus.
Protected
subscriptionsThe primary key of the user in the table.
The unique string-identifier of the user.
Readonly
uuidProtected
withRelations that should be eager-loaded by default.
Static
Protected
Readonly
CREATED_Optionally, the timestamp field set on creation.
Static
Protected
Readonly
UPDATED_Optionally, the timestamp field set op update.
Static
Protected
appendsArray of additional fields on the class that should be included in the object serializations.
Static
Protected
connectionThe name of the connection this model should run through.
Static
Protected
keyThe name of the column that uniquely identifies this model.
Static
Protected
masksArray of fields on the class that should be excluded from the object serializations.
Static
Protected
populateIf false (default), the primary key will be excluded from INSERTs.
Static
Protected
tableThe name of the table this model is stored in.
Static
Protected
timestampsIf true, the CREATED_AT and UPDATED_AT columns will be automatically set.
Private
appThe global application instance.
Protected
isProtected
Get a wrapped function that compares whether the given model field on the current instance differs from the originally fetched value.
Used to filter for dirty fields.
Protected
Get a wrapped function that compares whether the given model field on the current instance differs from the originally fetched value.
Used to filter for dirty fields.
Protected
appGet the global Application.
Apply the default scopes to this model to the given query builder.
Similar to assumeFromSource, but instead of mapping database fields to model
properties, this function assumes the object
contains a mapping of model properties
to the values of those properties.
Only properties with @Field()
annotations will be set.
Given a row from the database, set the properties on this model that correspond to fields on that database.
The row
maps database fields to values, and the values are set for the properties
that they correspond to based on the model's @Field()
annotations.
Create the inverse of a one-to-many relation. Should be called from a method on the model:
class MyModel extends Model<MyModel> {
@Related()
public otherModels() {
return this.hasMany(MyOtherModel)
}
}
class MyOtherModel extends Model<MyOtherModel> {
@Related()
public myModels() {
return this.belongsToMany(MyModel, 'otherModels')
}
}
Create the inverse of a one-to-one relation. Should be called from a method on the model:
class MyModel extends Model<MyModel> {
@Related()
public otherModel() {
return this.hasOne(MyOtherModel)
}
}
class MyOtherModel extends Model<MyOtherModel> {
@Related()
public myModel() {
return this.belongsToOne(MyModel, 'otherModel')
}
}
Initialize the model's properties from the given values and do any other initial setup.
values
can optionally be an object mapping model properties to the values of those
properties. Only properties with @Field()
annotations will be set.
Optional
values: { Protected
callProtected
containerGet the method with the given name from this class, bound to this class.
function
Get the method with the given name from this class, bound to this class.
function
Rest
...args: any[]Unique identifier of the user.
Protected
getProtected
getProtected
Get the relation instance returned by a method on this model.
Globally-unique identifier of the user.
Create a new one-to-one relation instance. Should be called from a method on the model:
class MyModel extends Model<MyModel> {
@Related()
public otherModels() {
return this.hasMany(MyOtherModel)
}
}
Optional
foreignKeyOverride: "push" | "toJSON" | "awareOfContainerLifecycle" | "key" | "all" | "count" | "pipe" | "getBoundMethod" | "exists" | "save" | "subscribe" | "uuid" | "up" | "down" | "isConnected" | "delete" | "rehydrate" | "query" | "relationCache" | "boot" | "getColumn" | "setColumn" | "assumeFromSource" | "assume" | "timestamps" | "qualify" | "qualifyKey" | "keyName" | "toQueryRow" | "dirtyToQueryRow" | "getOriginalValues" | "only" | "isDirty" | "isClean" | "wasChanged" | "getDirtyFields" | "touch" | "toObject" | "fresh" | "refresh" | "populate" | "is" | "isNot" | "hasOne" | "hasMany" | "belongsToOne" | "belongsToMany" | "getRelation" | "applyScopes" | "onContainerRelease" | "userId" | "username" | "firstName" | "lastName" | "passwordHash" | "getDisplay" | "getUniqueIdentifier" | "getIdentifier" | "verifyPassword" | "setPassword" | "validateCredential" | "dehydrate"Optional
localKeyOverride: keyof T2 & stringCreate a new one-to-one relation instance. Should be called from a method on the model:
class MyModel extends Model<MyModel> {
@Related()
public otherModel() {
return this.hasOne(MyOtherModel)
}
}
Optional
foreignKeyOverride: "push" | "toJSON" | "awareOfContainerLifecycle" | "key" | "all" | "count" | "pipe" | "getBoundMethod" | "exists" | "save" | "subscribe" | "uuid" | "up" | "down" | "isConnected" | "delete" | "rehydrate" | "query" | "relationCache" | "boot" | "getColumn" | "setColumn" | "assumeFromSource" | "assume" | "timestamps" | "qualify" | "qualifyKey" | "keyName" | "toQueryRow" | "dirtyToQueryRow" | "getOriginalValues" | "only" | "isDirty" | "isClean" | "wasChanged" | "getDirtyFields" | "touch" | "toObject" | "fresh" | "refresh" | "populate" | "is" | "isNot" | "hasOne" | "hasMany" | "belongsToOne" | "belongsToMany" | "getRelation" | "applyScopes" | "onContainerRelease" | "userId" | "username" | "firstName" | "lastName" | "passwordHash" | "getDisplay" | "getUniqueIdentifier" | "getIdentifier" | "verifyPassword" | "setPassword" | "validateCredential" | "dehydrate"Optional
localKeyOverride: keyof T2 & stringProtected
hasProtected
Returns true if the current model has a scope with the given identifier.
Protected
initializeProtected
makeProtected
namedProtected
Register a scope on the model with a specific name.
Return an object of only the given properties on this model.
Assume a
is an instance of some model A
with the given fields.
const a = new A({ field1: 'field1 value', field2: 'field2 value', id: 123 })
a.only('field1', 'id) // => {field1: 'field1 value', id: 123}
Rest
...fields: string[]Register a pipeline as an event handler.
Populates an instance of the model with the same database fields that are set on this model, with the exclusion of the primary key.
Useful for inserting copies of records.
Assume a record, a
, is an instance of some model A
with the given fields.
const a = A.find(123) // => A{id: 123, name: 'some_name', other_field: 'a value'}
const b = a.populate(new A) // => A{name: 'some_name', other_field: 'a value'}
Get a new query builder that yields instances of this model, pre-configured with this model's QuerySource, connection, and fields.
await user.query()
.where('name', 'LIKE', 'John Doe')
.update({ username: 'jdoe' })
Persist the model into the database. If the model already exists, perform an update on its fields. Otherwise, insert a new row with its fields.
Passing the withoutTimestamps
will prevent the configured CREATED_AT/UPDATED_AT
timestamps from being updated.
Protected
setProtected
shouldSubscribe to an event on the bus.
Protected
withProtected
Register a scope on the model.
Static
connectionStatic
findStatic
getStatic
getGet the database connection instance for this model's connection.
Static
getStatic
propertyStatic
qualifyStatic
qualifyStatic
queryGet a new query builder that yields instances of this model, pre-configured with this model's QuerySource, connection, and fields.
const user = await UserModel.query<UserModel>().where('name', 'LIKE', 'John Doe').first()
Static
queryGet the QuerySource object for this model as it should be applied to query builders.
This sets the alias for the model table equal to the table name itself, so it can be referenced explicitly in queries if necessary.
Static
setStatic
table
A basic ORM-driven user class.