-
Notifications
You must be signed in to change notification settings - Fork 0
Model
The base Model class for Mythix ORM. Every Mythix ORM model should inherit from this class. This class provides support for all model operations in Mythix ORM.
Notes:
- Many model methods have both static and instance
methods of the same name that do the same thing.
This is because it is common to access Model
methods directly on the model class as well as an
instance. For example, Model.static getModelName is both
a static method, and an instance method. Nearly all
the methods listed here have both a
staticand and instance version. We are only listing thestaticversions because the instance versions generally will just be proxies to thesestaticmethods. - An underscore prefix on a method in Mythix ORM implies that this method should not be overloaded unless you know exactly what you are doing. It also implies that there is another method that can and should be overloaded instead.
This property assists with type checking.
method Model::_castFieldValue(field: Field, value: any)
This casts a field value to its type, by calling the field's
field.type.castValuemethod for the type.Arguments:
field: FieldThe field to use to cast the value. The
typeproperty on the field will be accessed, and thetypepropertiescastValuemethod will be called on the providedvalueargument.value:anyThe value to cast to the field's type.
nullis a valid value, and allcastValuemethods on types should properly handle it.Return value:
anyThe value provided, cast to the type of the field.
This method simply creates the getters/setters for fields as described by Model._constructFields.
Arguments:
fieldNamefield
Construct the model's fields on the model instance. This method will iterate the
static Model.fieldsfields for the model. For each field (except virtual fields), it will callfield.type.exposeToModel(). If this method returnstrue, then the field will be added as a getter/setter to the model instance, with the name defined as the field'sfieldName. For example, if aUsermodel had a field namedfieldName: 'firstName', then thefirstNameproperty will be added to the model instance, as a getter/setter property on the instance. The getter/ setter provide the functionality of sending data in and out ofgetandsetmethods on the field itself, and through eachfield.type.castValuemethod on set. The setter will also mark a field as dirty if it is set to a value that is different from the current value of the field. The Model.getDataValue and Model.setDataValue instance methods will bypass the getter/setter of each field, allowing direct access to the underlying attribute value.
This is the final call the
constructormakes before it finalizes instantiating the model. It calls Model._constructFields to construct the model's fields, and then it calls Model._initializeModelData to initialize the field values for the model.Arguments:
data?:objectAttributes provided to the model through the
constructorcall.Return value:
undefined
method Model::_getConnection(connection?: Connection)
See Model.static _getConnection.
Arguments:
connection?: ConnectionAn optional connection that can be provided. If provided, it will simply be returned. Otherwise, if not provided, or a falsy value, then attempt to fallback to
modelInstance._connection, if that also fails to find a connection, the finally the method will call Model.static _getConnection to get the bound connection, if any is available.Return value: Connection
Notes:
- Pay attention that unlike Model.static _getConnection this checks the model's instance for
._connectionproperty. If that is a valid connection, then it will be returned before the bound connection. This is helpful when you have chosen not to bind a connection to your models. This will allow you to provide a connection directly when you create the model, which can make interacting with the model less tiresome. i.e.new Model(null, { connection }).
Get the dirty fields of the model instance. The model instance property
Model.changescalls this method to get the list of dirty fields for the model instance. UnlikeModel.changes, which is a getter, you can passoptionsto this method, which can change its behavior. Theoptionsargument has the following shape:{ connection: <see>Connection</see>, update: boolean, insert: boolean, // ... any options you wish to pass to `connection.dirtyFieldHelper` }If this method is provided a Connection via the
connectionoptions value, then it will assume it is being used in a connection method to fetch the dirty fields for a database operation (update, or insert). If it has a Connection then it will behave a little differently.The first difference is that if a model field is not marked as dirty, then it will be passed through connection.dirtyFieldHelper. If this method returns any value other than
undefined, then that value will be used as the "dirty" value for the field, and the field will be marked as dirty. This can be used when you want the connection itself to control the dirty state of a field. This is what is done with SQLite BigInt AUTOINCREMENT emulation. Any time an autoincrementing BigInt is being stored to a SQLite database with theemulateBigIntAutoIncrementoption enabled, an internal counter for this field is incremented, and the field is automatically updated as "dirty" (on insert only, if the field has andundefinedvalue).The next difference when using a
connectionin this method is that it will check if this is an "update" or an "insert" operation by checking theupdateandinsert"option" keys respectively. If one of these istrue, then it will invokedefaultValueproperty on the field, if saiddefaultValuehas theonUpdate, oronInsertflags set totrue. This can be used for example oncreated_at, andupdated_atfields, which will only be marked dirty and given a value on aninsertorupdateoperation through the connection.Without a
connectionprovided to this method, it will simply return the "change list" of all dirty fields on the model. The "change list" is an object, where each key is the name of the field, and each value is another object, withpreviousandcurrentkeys describe the change that took place to the field. For example:DirtyFieldChangeList = { firstName: { previous: undefined, current: 'Bob', }, }If no fields on the model are dirty, then an empty object will be returned. A field is considered "dirty" if its value is different from what it was when the model was first instantiated, or since the last time the Model.clearDirty method was called.
Arguments:
options?:objectOptions to provide to the method.
Return value:
DirtyFieldChangeListNotes:
- If this is an "update" or "insert" operation, as defined by the
updateorinsert"options", then the default value for the field will be fetched via the QueryGenerator.getFieldDefaultValue method through the providedconnection.
method Model::_getFieldValue(fieldName: string, field: Field)
Get a field's value. Calling this is no different from accessing the field directly on the model instance itself. For example,
userInstance.firstNameis identical to callinguserInstance._getFieldValue('firstName', User.fields.firstName).This will call the
getmethod defined on the field, if any is defined. If agetmethod is defined, then whatever value it returns will be the result of this method. If nogetmethod is defined on the field, thenthis.getDataValue(fieldName)is called instead, and will provide the resulting return value for this method.Arguments:
fieldName:stringThe name of the field whose value we wish to get.
field: FieldThe field definition itself for the value we wish to get.
Return value:
anyNotes:
- Never call this method (or the model attribute by name), while inside a field's
getmethod. If you do, you will enter an infinite recursive loop. Instead, call the providedgetmethod (as provided by the context), or call Model.getDataValue.See also: Field.get
method Model::_initializeFieldData(fieldName: string, field: Field, fieldValue: any, data: object)
Set each field's initial value. Each field's value will first be fetched from the
dataargument given to theconstructor--if any was given. After all field attributes have been set this way, then this method is called, being provided that value (if any) via thefieldValueargument. IffieldValueisundefined, then call thedefaultValueproperty of the field to get the field's initial value.Arguments:
fieldName:stringThe name of the field we are initializing.
field: FieldThe field definition itself for the field we are initializing.
fieldValue:anyThe field value as provided by the
dataargument to the modelconstructor, if any was provided.data:objectThe
dataargument, as provided to theconstructorof the model.
Initialize the field value for each field/attribute. If no
dataargument is passed to the constructor, then each field will be initialized to its default value, as defined by thedefaultValueproperty on each field. Anullvalue is a valid value, and though it will still be piped through each field'sfield.type.castValuemethod, it will discount the need to calldefaultValueon the field. This method calls Model._initializeFieldData to actually set the value of each field. Field values are set from the provideddataobject to theconstructorfirst, for all fields, before anydefaultValuecalls for any fields are attempted.Arguments:
data?:objectAttributes values for fields. Can be nothing, in which case the
defaultValueproperty for each field will be used instead.nullis a valid value, and if an attribute has anullvalue, it will not be given a default value fromdefaultValue.Notes:
- All fields have already been constructed before this method is called via Model._constructFields.
- Virtual fields are not constructed against the model instance, however, field types can modify the instance, and some do. For example, the
Types.ModelandTypes.Modelsvirtual field types inject relational methods on the model.- Only concrete fields are considered "attributes" of the model, and can have an initial value provided via the
dataargument to the constructor, or via adefaultValueproperty on the field.
method Model::_setFieldValue(fieldName: string, field: Field)
Set a field's value. Calling this is no different from setting the field directly on the model instance itself. For example,
userInstance.firstName = 'Bob'is identical to callinguserInstance._setFieldValue('firstName', User.fields.firstName, 'Bob').This will call the
setmethod defined on the field, if any is defined. If asetmethod is defined, then it is entirely up to thesetmethod to callthis.setDataValueto set the field's value. If nosetmethod is defined on the field, thenthis.setDataValue(fieldName, value)is called instead, and will set the value on the field.Arguments:
fieldName:stringThe name of the field whose value we wish to get.
field: FieldThe field definition itself for the value we wish to get.
Return value:
undefinedNotes:
- This method will mark the field as dirty if the value provided differs from the current value the field has.
- Never call this method (or set the model attribute by name), while inside a field's
setmethod. If you do, you will enter an infinite recursive loop. Instead, call the providedsetmethod (as provided by the context), or call Model.setDataValue.See also: Field.set
Clear the dirty state of the model, or of a single field. If a
fieldNameargument is provided, then only the specified field's "dirty" status will be cleared. If nofieldNameargument is provided, then all field's on the model will have their "dirty" status cleared, and the model will no longer be "dirty".The "dirty" status of a field is cleared by 1) setting the real underlying field value (this._fieldData) to the dirty field value, and 2) removing the entry in
this._dirtyFieldDataon the model for the field.Arguments:
fieldName?:stringIf specified, clear only this field's "dirty" status. If not specified, clear all fields on the model, making the entire model no longer dirty.
Return value:
boolean
Construct a new Model instance.
Arguments:
data?:objectAttributes to provide to the new model instance. The key names should be a
fieldName, not acolumnName. Any model attribute missing fromdata, or whose value isundefined, will be given a default value from thedefaultValue, field property for the field. If thedefaultValuefor the field is marked as a "remote" value (a value provided by the database) or ifdefaultValueis not marked with the flagFLAG_ON_INITIALIZE, then the field will remain with a value ofundefined, at least until the model is stored to the database. The default for all methods provided to thedefaultValuekey of the field is to have theFLAG_ON_INITIALIZEflag, so the value will be created on model instantiation. Some default value methods however, such asAUTOINCREMENT, do not have theFLAG_ON_INITIALIZEset, because the defaultValue is provided by the database.nullis a valid value, and if provided for an attribute, then thedefaultValuewill not be used. Any attribute value provided will go throughfield.type.castValuefrom the fieldtypeproperty (this includesnullvalues). Any attributes provided will immediately be marked as "dirty" as soon as the model is instantiated.options?:objectOptions for the model. The only property Mythix ORM will use is the
connectionkey. If provided, it will set this as the_connectionproperty on the instance. Otherwise, these options are intended to be used by you, the developer, to do with as you please on your models. They can be fetched from any model instance simply by calling Model.getOptions.Return value: Model
Destroy this model instance.
Calling this method will destroy this model from the database. If the model is not persisted, then nothing will happen, and
0will be returned. If the model is persisted, the result of Connection.destroy is returned, which is the number of rows modified in the database, which in this case should always be1.If the model has no primary key field defined, then an exception will be thrown.
Arguments:
options?:objectOptions to pass to the underlying QueryEngine.destroy call. If a
connectionproperty is present on this options object, then it will be used as the connection for this operation.Return value:
numberThe number of rows modified in the database.
Notes:
- A primary key is required on the model for this method to work. If you don't have a primary key defined, then you will need to create your own "destroy" operation.
Get all the models current raw attributes. This will return an object, where each key is the
fieldNameof each non-virtual (concrete) field on the model, and each value is the "current" value of the field on the model. The "current" value for each field could either be a dirty field value, or a clean (or raw) field value.This method is nearly identical to Model.toJSON except that Model.toJSON always adds the primary key to the result first, which only matters for JavaScript engines that honor the insertion order of keys in native Objects, which is never guaranteed. Model.toJSON also differs from this method by calling
field.type.serializefor every attribute on the model.Return value:
objectAll models attributes (field values).
Notes:
- Field's with
undefinedvalues will not be included in the resulting object.
Get the current value of any field on the model. The "current" value will be the dirty value if the field is dirty, or it will be the clean value of the field if the field isn't dirty.
This method is a "raw" get of the field's value in that it won't call
geton the field descriptor, if any is defined. Instead it will first attempt to fetch the current value of the field fromthis._dirtyFieldData, if there is an entry for the field in thethis._dirtyFieldDataproperty of the model instance. If there is no "dirty" entry for the field, then its "clean value" (or raw value) will be fetched from the underlyingthis._fieldDatastorage area for field values.Arguments:
fieldName:stringThe name of the field whose value you wish to fetch.
Return value:
any
Get the dirty field descriptors themselves for all fields that are dirty.
Whereas Model._getDirtyFields returns a "change list" of dirty fields, this method will return the field descriptors themselves. An array of Field will be returned for each dirty field, or an empty array if no fields are dirty.
Arguments:
options?:objectIf provided, this will be the "options" supplied to Model._getDirtyFields.
Return value: Array<Field>
The dirty fields of the model.
Get the options provided to the model, if any. This will always return an object, even if no options were provided, in which case the object will simply be an empty object.
Return value:
objectOptions object provided by the user to the model when the model was constructed.
Checks if the primary key's value is valid. Validity checks are handled by the field's
type. When this method is called, the primary key field for the model is fetched, and if found, thefield.type.isValidValuemethod will be called and provided with the current value of the primary key field.Type.isValidValue is commonly implemented to be a strict check against the type.
nullwill generally returnfalsefor anisValidValuecall, however implementation details are entirely left up to theisValidValuemethod defined on the type.Return value:
boolean
Check if the model is dirty or not. If a
fieldNameis provided as an argument, it will only check if the specified field is dirty or not. If not provided, then the entire model will be considered "dirty" if one or more fields are marked as "dirty".Arguments:
fieldName?:stringIf provided, check if this one field is dirty. If not provided, then check if any field on the model is dirty.
Return value:
boolean
Check if the model is persisted or not. This has nothing to do with the model's "dirty" state. if the model is dirty, then this will still report
trueif the model was initially loaded from the database.Return value:
boolean
trueif the model was loaded from the database,falseotherwise.
After insert model hook.
This method will be called on each model instance after it has been inserted into the database. This method is called after each model instance has been fully stored, marked as persisted, and marked as not dirty. If you set any model fields in this method, then the model will be marked as dirty, and will be re-saved at the end of the insert operation.
Arguments:
context:objectA context object that is provided to all model hooks. The shape of this object is
{ connection, Model, options }. It will contain the currentconnectionfor the operation (which might be a transaction connection), theModelfor the operation, which is the "root model" of the operation, not necessarily "this" model (the model whose hook is being called), and the "options" defined for the current operation. eslint-disable-next-line no-unused-vars.Notes:
- Use care when updating model attributes in this method. At the end of each insert operation, the models just stored are scanned to see if any of them are dirty. If they are dirty they will be re-stored to the database using an update operation. This can happen for example if foreign keys are in use. We might not be able to update a foreign key field value until after the insert operation is completed. When a foreign key value is updated post-insert, then the model might again become dirty, and be updated post-insert. Because of this, you should be careful about making your model dirty in any "after" hooks, as you might unintentionally incur the cost of a post-insert update.
After insert or update model hook.
This method will be called on each model instance after it has been inserted or updated in the database. This method is called after each model instance has been fully stored, marked as persisted, and marked as not dirty. If this is an insert operation, and if you set any model fields in this method, then the model will be marked as dirty, and will be re-saved at the end of the insert operation.
Arguments:
context:objectA context object that is provided to all model hooks. The shape of this object is
{ connection, Model, options }. It will contain the currentconnectionfor the operation (which might be a transaction connection), theModelfor the operation, which is the "root model" of the operation, not necessarily "this" model (the model whose hook is being called), and the "options" defined for the current operation. eslint-disable-next-line no-unused-vars.Notes:
- Use care when updating model attributes in this method. At the end of each insert operation, the models just stored are scanned to see if any of them are dirty. If they are dirty they will be re-stored to the database using an update operation. This can happen for example if foreign keys are in use. We might not be able to update a foreign key field value until after the insert operation is completed. When a foreign key value is updated post-insert, then the model might again become dirty, and be updated post-insert. Because of this, you should be careful about making your model dirty in any "after" hooks, as you might unintentionally incur the cost of a post-insert update.
After update model hook.
This method will be called on each model instance after it has been update in the database. This method is called after each model instance has been fully stored, marked as persisted, and marked as not dirty. Unlike an insert operation, update operations do not have a post-operation dirty model scan and re-update. You can safely update model attributes in this method without the worry of incurring the cost of an extra store operation. However, if you do set model attributes in this method, then the model will be marked dirty when the update operation is complete.
Arguments:
context:objectA context object that is provided to all model hooks. The shape of this object is
{ connection, Model, options }. It will contain the currentconnectionfor the operation (which might be a transaction connection), theModelfor the operation, which is the "root model" of the operation, not necessarily "this" model (the model whose hook is being called), and the "options" defined for the current operation. eslint-disable-next-line no-unused-vars.
Before insert model hook.
This method will be called on each model instance before it is inserted into the database. This method is called before dirty fields are calculated for the insert operation, so you can set field values here before insert, and they will be captured and inserted into the database.
Arguments:
context:objectA context object that is provided to all model hooks. The shape of this object is
{ connection, Model, options }. It will contain the currentconnectionfor the operation (which might be a transaction connection), theModelfor the operation, which is the "root model" of the operation, not necessarily "this" model (the model whose hook is being called), and the "options" defined for the current operation. eslint-disable-next-line no-unused-vars.
Before save model hook.
This method will be called on each model instance before it is inserted or updated in the database. This method is called before dirty fields are calculated for the insert or update operation, so you can set field values here before update, and they will be captured and updated in the database.
Arguments:
context:objectA context object that is provided to all model hooks. The shape of this object is
{ connection, Model, options }. It will contain the currentconnectionfor the operation (which might be a transaction connection), theModelfor the operation, which is the "root model" of the operation, not necessarily "this" model (the model whose hook is being called), and the "options" defined for the current operation. eslint-disable-next-line no-unused-vars.Notes:
- This is the final hook call before the insert or update operation sends your data off to the database.
Before update model hook.
This method will be called on each model instance before it is updated in the database. This method is called before dirty fields are calculated for the update operation, so you can set field values here before update, and they will be captured and updated in the database.
Arguments:
context:objectA context object that is provided to all model hooks. The shape of this object is
{ connection, Model, options }. It will contain the currentconnectionfor the operation (which might be a transaction connection), theModelfor the operation, which is the "root model" of the operation, not necessarily "this" model (the model whose hook is being called), and the "options" defined for the current operation. eslint-disable-next-line no-unused-vars.
Validate all concrete fields on the model. This method is called before any "insert" or "update" operation happens for the model. It will iterate all the fields of the model, and call the
validatemethod defined on each field descriptor (Field), if any is defined. Eachvalidatemethod is asynchronous, so all promises will be collected from allvalidatemethod calls, and will be awaited upon viaawait Promise.all(validatePromises);.Model validation will fail if any
validatemethod throws an exception.
onValidateis called directly from Model.onBeforeSave, so make certain you callsuper.onBeforeSave(...args)if you overloadonBeforeSave. If you don't, your validation hooks won't be called. This design was deliberate, so the developer could choose to bypass model validation on purpose simply by not callingsuper.onBeforeSave(...args)should they choose not to.Feel free to overload
onValidateto provide your own implementation.Arguments:
context:objectA context object that is provided to all model hooks. The shape of this object is
{ connection, Model, options }. It will contain the currentconnectionfor the operation (which might be a transaction connection), theModelfor the operation, which is the "root model" of the operation, not necessarily "this" model (the model whose hook is being called), and the "options" defined for the current operation.Return value:
Array<any>Results of each
validatecall from each field. Will generally beundefinedfor each call. The validation for a field will only fail if an exception is thrown.falseornullas a return value from avalidatecall is meaningless (unless you yourself wish to do something with it).Notes:
validateproperties on fields must always be methods. Unlike other ORMs, we don't allow a pattern, a RegExp, or anything else. You must provide the implementation of eachvalidatemethod directly yourself (which could for example use a RegExp to check the field's value).
Reload the model in-place.
This method will create a query selecting this model from the database by its primary key. It will then take the columns from the select operation, and will apply the values to the model's fields in-place.
If a row is returned from the database, then the model's fields will be updated,
this.clearDirty()will be called to clear the dirty status of the model, and finally the model will be marked as persisted.If no row is returned from the database, then this method will immediately return, and the model won't be updated.
If the model has no primary key field defined, then an exception will be thrown.
Arguments:
options?:objectOptions to pass to the underlying QueryEngine.first call. If a
connectionproperty is present on this options object, then it will be used as the connection for this operation.Return value:
undefinedNotes:
- A primary key is required on the model for this method to work. If you don't have a primary key defined, then you will need to create your own "reload" operation.
Persist the model to the database.
This method will either initiate an insert operation against the model (if
this.isPersisted()returnsfalse), or initiate an update operation ( ifthis.isPersisted()returnstrue).This method will do nothing, and immediately return
falseif the model is not dirty. If you provide the optionforce: trueas a property in theoptionsargument, then all fields will forcefully be marked as dirty, using the current field's value as the "dirty" value for each field, and then the model will be either inserted or updated, based on the result fromisPersisted. Usingforce: truewill essentially send and insert or update operation through the connection that will update ALL columns for the model row in the database, regardless of if they were actually dirty or not.At the end of this method--assuming the operation was successful--
this.clearDirty()will be called on the model instance to clear its dirty state, and then the model will be marked as persisted. Finally,truewill be returned, letting the caller know the operation completed successfully.Arguments:
options?:objectOptions to pass to the underlying connection Connection.insert or Connection.update call. If a
connectionproperty is present on this options object, then it will be used as the connection for this operation.Return value:
boolean
trueif the model was persisted through the database, orfalseotherwise.falsedoesn't mean there was an error. Errors will be thrown.falsesimply means that the model had no dirty fields, so it was never sent to the database.
Set attributes on the model via the provided object. The provided object should contain keys that are field names for each field you wish to set. The value of each key will be what is set onto the field. This method ignores virtual fields, so if any virtual field names are supplied, then will be silently skipped. This method is identical to calling
modelInstance[fieldName] = valueon every key in the object provided.Arguments:
attributes:object|ModelThe attributes to set on the model. The keys of the model should be field names.
noPrimaryKey:booleanIf
true, then the primary key of the model (if any is defined) will be skipped, and won't be set, even if the providedattributesargument contains a value for the primary key.Return value:
undefinedNotes:
- Any
undefinedvalue in the provided object will be ignored, and no update will occur for the field.- If a raw object instead of a model instance is provided, then
hasOwnPropertyis called for each field name, and if the provided object doesn't contain its "own" property matching the field name, the field will be silently skipped, and not set.
Set the current value of any field on the model. The "current" value will be the dirty value if the field is dirty, or it will be the clean value of the field if the field isn't dirty.
This method is a "raw" set of the field's value in that it won't call
seton the field descriptor, if any is defined. Instead, it will mark the field as dirty by setting the value provided as an entry for the field in thethis._dirtyFieldDataproperty of the model instance. If the value set is equal to the "clean value" of the field, as found inthis._fieldData, then the dirty entry for the field will be cleared (deleted) instead.Arguments:
fieldName:stringThe name of the field whose value you wish to set.
value:anyValue to set the field to. The will be sent through
field.type.castValueto cast the incoming value to the field's type.Return value:
undefinedNotes:
- This method will always call Model.updateDirtyID, invalidating all down-stream cache for this model instance.
static method Model::_getConnection(connection?: Connection)
Get the underlying connection bound to the model's class. Connection binding is optional, so this method can also be provided a connection. If a connection is provided, then it will simply be returned. Because Mythix ORM has no globals, this is a design pattern to supply a connection if you have one available, or fallback to a "bound" connection (if one can be found).
Arguments:
connection?: ConnectionAn optional connection that can be provided. If provided, it will simply be returned. Otherwise, if not provided, or a falsy value, then attempt to fallback to the bound connection, if any is available.
Return value: Connection
Fetch all models from the database for this model type.
Arguments:
options?:objectAn "options" object to pass off to the underlying Connection methods. If a
connectionkey is specified in this object, then that will be used as the connection for the operation. This can be important if for example you are calling this from atransaction, in which case you most certainly would want to provide theconnectionfor the transaction. If astream: trueoption is provided, then an async generator will be returned, allowing you to "stream" the rows from the database in batches. The defaultbatchSizeis500, but can be overridden by setting thebatchSizeoption to some valid positive number, orInfinityto pull everything at once. If thestreamoption is not specified, or isfalse, then all rows will be fetched from the database in batches, collected into an array, and returned only once all rows have been fetched. This is the default behavior.Return value: Array<Model>
Return all models of this type from the database.
Notes:
- This will fetch ALL rows for the model. If this is not what you want, then construct a query first, and call
allfrom the query itself, i.e.User.where.firstName.EQ('Bob').all(options).
static method Model::bindConnection(connection?: Connection)
A Connection instance will call this method on a Model class to bind the model to the connection. Overload this to change the behavior of binding connections to models. This method should return a model class. The default behavior is to return
thisclass. However, you might return a different class for example if you generated a new class that inherited fromthisclass.Arguments:
connection?: ConnectionThe connection instance to bind to this model class.
Return value: class extends Model
Count the rows in the database for this model.
Arguments:
options?:objectAn "options" object to pass off to the underlying Connection methods. If a
connectionkey is specified in this object, then that will be used as the connection for the operation. This can be important if for example you are calling this from atransaction, in which case you most certainly would want to provide theconnectionfor the transaction.Return value:
numberReturn the number of models stored in the database for this model type.
static method Model::create(models: Array<Model> | Model | Array<object> | object, options?: object)
Create (insert) new models into the database. The
modelsargument can be a single model instance, a single object containing model attributes, an array of model instances, or an array of objects containing model attributes. This is a "bulk" create method, though it can be used to create a single model.Arguments:
models: Array<Model> | Model |Array<object>|objectSpecify the model(s) to create.
options?:objectAn "options" object to pass off to the underlying Connection methods. If a
connectionkey is specified in this object, then that will be used as the connection for the operation. This can be important if for example you are calling this from atransaction, in which case you most certainly would want to provide theconnectionfor the transaction.Return value: Model
Return the model instance(s) created.
static method Model::defaultScope(query: QueryEngine)
One can apply a "default scope" to any model simply by providing this static method on the model. By default it will simply return the derp instance (a query) that it was provided.
The way this works is simple. The caller provides the query as the first and only argument. The user, by overloading this method can then easily modify this provided query, changing the "default scope" whenever the model is used for queries. For example, let's say you have a User model, and by default, you only want to query against Users that have their
activecolumn set totrue. In order to do this, you could easily provide astatic defaultScopemethod on your model class that would modify the base query. See the following example:Example:
class User extends Model { static defaultScope(baseQuery) { // `baseQuery` is equal to `User.where` // without a default scope. return baseQuery.active.EQ(true); } }Arguments:
query: QueryEngineThe query that you should add onto.
Return value: QueryEngine
Get the first (limit) rows from the database for this model type.
Arguments:
limit?:number(Default:1)The number of model instances to fetch from the database.
options?:objectAn "options" object to pass off to the underlying Connection methods. If a
connectionkey is specified in this object, then that will be used as the connection for the operation. This can be important if for example you are calling this from atransaction, in which case you most certainly would want to provide theconnectionfor the transaction.Return value: Model | Array<Model>
Return
limitmodels of this type from the database. Iflimitisnull,undefined, or1, then a single model instance will be returned (orundefinedif nothing is found). If thelimitargument is more than1, then an array of model instances will be returned, or an empty array if nothing is found.Notes:
- This will fetch the first rows for the model, in database order. If you wish to filter, and specify the order, then construct a query first, and call the
firstmethod from the query itself, i.e.User.where.firstName.EQ('Bob').ORDER('+User:firstName').first(options)
Count the number of concrete fields on the model. "concrete" fields are non-virtual fields that are backed by the database. A
FOREIGN_KEYfield is a concrete field, soFOREIGN_KEYfields will be counted.Return value:
numberThe number of concrete fields the model has.
static method Model::getConnection(connection?: Connection)
Get the underlying connection bound to the model's class. Connection binding is optional, so this method can also be provided a connection. If a connection is provided, then it will simply be returned. Because Mythix ORM has no globals, this is a design pattern to supply a connection if you have one available, or fallback to a "bound" connection (if one can be found). This method should be overloaded if you wish to provide your own model specific connection.
Arguments:
connection?: ConnectionAn optional connection that can be provided. If provided, it will simply be returned. Otherwise, if not provided, or a falsy value, then attempt to fallback to the bound connection, if any is available.
Return value: Connection
Specify the default SELECT "ORDER" for the model. This method will be called if no "ORDER" was specified for any given query. This method should return an Array of fully qualified field names. The
optionsargument is the current options for the specific query being operated on.Arguments:
optionsReturn value:
Array<string>|nullAn array of fully qualified field names to specify the ORDER. Prefix a field name with
+to specify ASCending order, i.e.[ "+User:id" ]. Prefix the field name with-to specify DESCending order, i.e.[ "-User:id" ].Notes:
- Internally, Mythix ORM will call
this.connection.getDefaultOrder(options), which--if not overloaded--will simply call this method from the model itself.- A "fully qualified field name" in Mythix ORM means a full field definition, including the model name. An example of a fully qualified field name might be
"User:id". The model name is separated from the field name by a colon:. A short hand, not fully qualified field name example would be simply"id". Since this contains no model prefix, this is "short hand", and is not a fully qualified field name.
Get a specific model field by field name. This method will return
undefinedif the specified field can not be found on the model. This will find both concrete and virtual fields that are defined on the model.Arguments:
fieldName:stringThe specified field name to find. This is not the
columnNameof the field.Return value: Field
Notes:
- In Mythix ORM you never specify a field via its
columnName. You always use a field's definedfieldNameto match against a field. Using acolumnNamesimply won't work, unlesscolumnNameandfieldNamejust happen to have the same value.
Get the fields for this model. You can optionally specify the
fieldNamesargument, which will cause the method to return only the fields specified by name. If thefieldNamesargument is provided, then the return value will always be an array of fields. If thefieldNamesargument is not provided, then the return value could be either an Array of fields, or an object of fields, keyed by field name (depending on how you defined your model fields).Arguments:
fieldNames?:Array<string>An array of field names to fetch. If not provided then all model fields will be returned, including virtual fields.
Return value: Array<Field> | Object<string, Field>
Notes:
- The first time this method is called the model's fields will be built, and possibly modified. All fields will be turned into Field instances, and each field will be properly constructed to include required attributes, such as their parent
Model, theirfieldName, and theircolumnName. A model's fields are always initialized when the model is first bound to a connection, or when this method is first called.- In Mythix ORM you never specify a field via its
columnName. You always use a field's definedfieldNameto match against a field. Using acolumnNamesimply won't work, unlesscolumnNameandfieldNamejust happen to have the same value.
static method Model::getForeignKeyFieldsMap(connection?: Connection)
Return the foreign key relationships for the model.
Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
Return value:
Map<string, array<object>>The format is
Map[modelName] = [ { targetFieldName, sourceFieldName }, ... ]
static method Model::getForeignKeysTargetField(connection?: Connection, modelName: string, fieldName: string)
Get a specific foreign key field's relationship information. This will be what is stored in the relationship field map for the specified target field. See Model.static getForeignKeyFieldsMap for more information.
Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
modelName:stringThe model name for which you wish to fetch foreign key fields from.
fieldName:stringThe field name for which you wish to fetch foreign key relational information about.
Return value:
object<{ targetFieldName, sourceFieldName }>This will be the relationship info for this foreign key field which will be an object of the shape
{ targetFieldName, sourceFieldName }.
static method Model::getForeignKeysTargetFieldNames(connection?: Connection, modelName: string)
Return all the foreign key target field names. This will return the target field names of all foreign key fields specified on the model.
Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
modelName:stringThe model name for which you wish to fetch foreign key fields from.
Return value:
Array<string>The format is
Array[] = modelName
static method Model::getForeignKeysTargetModelNames(connection?: Connection)
Return all the foreign key target model names. This will be all models targeted by all foreign keys defined by foreign key fields on this model. This will only return the models name's.
Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
Return value:
Array<string>The format is
Array[] = modelName
static method Model::getForeignKeysTargetModels(connection?: Connection)
Return all the foreign key target models. This will be all models targeted by all foreign keys defined by foreign key fields on this model.
Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
Return value:
Map<string, Model>The format is
Map[modelName] = Model
Get the Model class for this model.
Return value: class Model
Get the model name for this model. By default this will be the name of the class itself, i.e.
this.name. Overload this method to provide your own model name (singular name).Return value:
stringThe name the model.
Get the plural model name for this model. By default this will be the singular name of the model, converted to plural using the Inflection library. Overload this method to provide your own plural name for the model.
Return value:
stringThe name the model in plural form.
Notes:
- This will return the "plural" name of the model.
See also: Model.static getSingularName
Get the primary key field of the model, if any is defined. If no primary key field is defined, then this will return
undefined. A primary key is specified per-model by usingprimaryKey: trueon one (and only one) of the model's fields.Return value: Field
Get the name of the primary key field of the model, if any is defined. If no primary key field is defined, then this will return
undefined. A primary key is specified per-model by usingprimaryKey: trueon one (and only one) of the model's fields.Return value:
string
static method Model::getQueryEngine(connection?: Connection, options?: object)
This method is called any time a
Model.whereorModel.$property is accessed. It returns a query, based off this model class (as the root model). It will first call Model.static getUnscopedQueryEngine to get the root query for the model, and then it will call Model.static defaultScope to apply any default scope to the root query. Finally, it will return the query to the user to start interacting with.Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
options?:objectAny extra options to pass to the QueryEngine constructor.
Return value: QueryEngine
static method Model::getQueryEngineClass(connection?: Connection)
This method is called every time a
Model.whereorModel.$property is accessed. It should return a class that inherits from (or is)QueryEngine. By default, it will callthis.getConnection().getQueryEngineClass()to get the query class defined in the connection options. Though this can be overloaded per-model (creating a different type ofQueryEngineper-model), theQueryEngineclass to instantiate to use for queries will generally be supplied by the connection.Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
Return value: class QueryEngine
Get the singular model name for this model. By default this will be the name of the class itself, i.e.
this.name. You should probably overload Model.static getModelName to provide your own model name, instead of overloading this method.Return value:
stringThe name the model in singular form.
Notes:
- This will return the "singular" name of the model which is the same as Model.static getModelName.
- This method simply calls Model.static getModelName to get the singular model name.
See also: Model.static getPluralModelName, Model.static getModelName
This method is identical to Model.static getFields except that it will always return an Array of fields, and the fields will always be sorted by their
fieldName.Arguments:
fieldNames?:Array<string>An array of field names to fetch. If not provided then all model fields will be returned, including virtual fields.
Return value: Array<Field>
Notes:
- In Mythix ORM you never specify a field via its
columnName. You always use a field's definedfieldNameto match against a field. Using acolumnNamesimply won't work, unlesscolumnNameandfieldNamejust happen to have the same value.
static method Model::getTableName(connection?: Connection)
Get the table name for this model. By default Mythix ORM will take the model's name, and convert it to snake_case.
Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
Return value:
stringThe name of the table for this model.
static method Model::getUnscopedQueryEngine(connection?: Connection, options?: object)
This method is called any time a
query.unscoped()call is made. It will return the query's "root class"wherewith no Model.static defaultScope scope applied. Calling "unscoped()" will reset the query, so make sure you always call it first:Model.where.unscoped()...Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
options?:objectAny extra options to pass to the QueryEngine constructor.
Return value: QueryEngine
This method is called anytime a
Model.whereorModel.$attribute is accessed. It will provide the instantiated QueryEngine with the connection specified (if any). A connection can be specified for example by doingModel.where(connection)orModel.$(connection). This is generally only useful if you have chosen not to bind your models to a connection.Arguments:
options?:object { connection: Connection }An object, which if supplied, should contain a
connectionkey, specifying the connection. If no connection is provided, then this will fallback tothis.getConnection()to try and find the connection itself.Return value: QueryEngine
A QueryEngine instance (a query) for this model.
Check if the model has the specified field by name. If the specified field is found on the model, then return
true, otherwisefalsewill be returned.Arguments:
fieldName:stringThe specified field name to find. This is not the
columnNameof the field.Return value:
booleanNotes:
- In Mythix ORM you never specify a field via its
columnName. You always use a field's definedfieldNameto match against a field. Using acolumnNamesimply won't work, unlesscolumnNameandfieldNamejust happen to have the same value.
Check if any of the model's fields have a "remote value" as a
defaultValue. AdefaultValuemethod can itself report that it is "remote", meaning it is a value provided by the database itself. This method simply iterates all the model's fields, and callsfield.type.isRemote()on each field. Iffield.type.isRemote()returnstruefor any field, then this method will returntrue, otherwise it will returnfalse. Use this method to know if the model contains any fields whose value is obtained directly from the database itself (i.e. primary key date fields, etc...).Return value:
boolean
static method Model::initializeFields(fields: Array<Field> | Set<Field> | Object<string, Field> | Map<string, Field>)
Initialize all fields for the model. This will be called anytime a Model.static getFields call is made. However, it caches its results, so it will immediately return if the model's fields have already been initialized.
This method does a number of things in the process of "initializing" model fields. It first ensures that every field is an instance of Field. Second, it ensures that the Type of the field is initialized (properly instantiated). Third, it ensures that all required attributes of each field is present. Required attributes are
Model(the parent model),fieldName(the name of this field), andcolumnName(the column name for the DB).columnName, if not provided, will simply becomefieldName.Arguments:
fields: Array<Field> | Set<Field> | Object<string, Field> | Map<string, Field>A list of fields to work off of. When this method is called by Model.static getFields, then this argument will be
static Model.fields.Return value: Array<Field> | object<string, Field>
Notes:
- The cache for built fields is stored directly on the input
fieldsargument, under a non-enumerable_mythixFieldsInitializedcache key.
static method Model::isForeignKeyTargetModel(connection?: Connection, modelName: string)
Check if the specified model is a model pointed to by a foreign key field.
Arguments:
connection?: ConnectionAn optional connection to pass through. This is needed if your models are not bound to a connection.
modelName:stringThe model name for which you wish to fetch foreign key fields from.
Return value:
boolean
trueif the specifiedmodelNamemodel is pointed to by one of the foreign key fields,falseotherwise.
Check to see if the provided value is an instance of a Mythix ORM Model. Unlike Model.static isModelClass, which checks if a class is a Model, this will check to see if an instance is an instance of a Mythix ORM Model. It will return
trueif the provided value is aninstanceofModel, or if the value'sconstructorproperty has a truthy_isMythixModelproperty (value.constructor._isMythixModel).Arguments:
value:anyValue to check.
Return value:
boolean
Use this method to check if a class is a Mythix ORM model. It will return
trueif the provided value is a class that inherits from Model, or if the provided value has an attribute named_isMythixModelthat is truthy.Arguments:
value:FunctionValue to check.
Return value:
boolean
static method Model::iterateFields(callback: Function(context: IterationContext), fields?: Array<Field> | Set<Field> | Object<string, Field> | Map<string, Field> = null, sorted?: boolean = false)
Iterate all model fields. This is a convenience method to iterate
static Model.fields, and is needed as the fields of a model can be anArray, anobject, aMap, or aSet. This method works a lot likeArray.prototype.map. Any return value from the providedcallbackwill be pushed into an array just likeArray.prototype.map. Thecallbackprovided, when called, will be provided acontextobject, as the single argument to the callback. This context object has the following shape:IterationContext = { // The Field instance itself. field, // The name of the field. fieldName, // All the model's fields. fields, // The current index into the list of fields. // This will be set even if the fields are // `object` or `Map` types. index, // A method that when called will halt // iteration and immediately return. stop, // A method that you can call to see // if `stop` has been called... meaning the // iteration process is about to halt. isStopped, }At any time you can call the
stopmethod provided via the context. When called,iterateFieldswill stop iterating, and immediately return an array of results returned by all calls tocallback.Arguments:
callback:Function(context: IterationContext)A callback method that will be called for every field on the model.
fields?: Array<Field> | Set<Field> | Object<string, Field> | Map<string, Field> (Default:null)An optional list of fields to use instead of
static Model.fields. This is handy if, for example, you want to iterate a sub-set of the model's fields, such as the "dirty" fields reported by the model.sorted?:boolean(Default:false)If
true, then sort the model fields before iterating. Iffalse, simply iterate the model's fields in their defined order.Return value:
Array<any>
Get the last (limit) rows from the database for this model type.
Arguments:
limit?:number(Default:1)The number of model instances to fetch from the database.
options?:objectAn "options" object to pass off to the underlying Connection methods. If a
connectionkey is specified in this object, then that will be used as the connection for the operation. This can be important if for example you are calling this from atransaction, in which case you most certainly would want to provide theconnectionfor the transaction.Return value: Model | Array<Model>
Return
limitmodels of this type from the database. Iflimitisnull,undefined, or1, then a single model instance will be returned (orundefinedif nothing is found). If thelimitargument is more than1, then an array of model instances will be returned, or an empty array if nothing is found.Notes:
- This will fetch the last rows for the model, in database order. If you wish to filter, and specify the order, then construct a query first, and call the
lastmethod from the query itself, i.e.User.where.firstName.EQ('Bob').ORDER('+User:firstName').last(options)- This works by telling the underlying query generator to invert the specified ORDER of the query, and then it selects the first
limitrows from the result.
static method Model::mergeFields(mergeFields?: Array<Field> | Set<Field> | Object<string, Field> | Map<string, Field>)
Merge specified fields into this model's fields. The
mergeFieldsargument is optional. If not provided, then this method will simply clone the model's fields. If specified, then the fields provided will be merged into the existing fields. Merging takes place based on each field'sfieldNameattribute. ThemergeFieldsargument can be anArray, anobject, aMap, or aSet. Fields are matched based onfieldName, but when a match is found, it is completely overridden by what is found in themergeFieldsargument. In short, the list of fields itself is merged, but the fields themselves are not merged (a shallow merge). All input objects that have keys (Object<string, Field> | Map<string, Field>) must specify thefieldNameof the field as the key. If the input is an Array type (Array<Field> | Set<Field>) then each field must contain afieldNameattribute, or an exception will be thrown.</string,></string,>.Arguments:
mergeFields?: Array<Field> | Set<Field> | Object<string, Field> | Map<string, Field>A list of fields to merge into the current model fields. The field list, as well as all fields will be cloned.
Return value: Array<Field> | object<string, Field>
Notes:
Pluck specific fields (columns) from the database for this model type.
Arguments:
fields?:Array<string>An array of fully qualified field names to pluck from the underlying database table for this model. Do not use column names here... these must be fully qualified field names.
options?:objectAn "options" object to pass off to the underlying Connection methods. If a
connectionkey is specified in this object, then that will be used as the connection for the operation. This can be important if for example you are calling this from atransaction, in which case you most certainly would want to provide theconnectionfor the transaction.Return value:
Array<any>|Array<Array<any>>If only a single field is specified, then a flat array of values will be returned across all rows. If more than one field is specified, then an array of arrays (rows) will be returned for the fields specified.
Notes:
- This will pluck across ALL rows for the model, in database order. If you wish to filter and limit, and specify the order, then construct a query first, and call the
pluckmethod from the query itself, i.e.User.where.firstName.EQ('Bob').LIMIT(50).ORDER('+User:firstName').pluck([ 'User:firstName' ], options)- In Mythix ORM you never specify a field via its
columnName. You always use a field's definedfieldNameto match against a field. Using acolumnNamesimply won't work, unlesscolumnNameandfieldNamejust happen to have the same value.
Check to see if the primary key field (if any is defined) has a "remote" default value. For example, an autoincrementing primary key field would return
truefrom this method, because an autoincrementing field value is retrieved directly from the database. This could returnfalse, if for example, you were using UUIDs, or XIDs for your primary key.Return value:
boolean
trueif the primary key field of the model has a "remote"defaultValue,falseotherwise. Remoteness is checked viathis.getPrimaryKeyField().type.isRemote().
Like everywhere in Javascript, we can call
.toString()to a get a string representation of our Model class. The optionalshowFieldsargument, if true, will list the models fields as well. Without theshowFieldsargument, the model name alone will be returned as a string.Arguments:
showFields?:booleanIf
true, then list the models fields.Return value:
string
Return a raw Object of the model's attributes, ready to be passed through
JSON.stringify. This method is nearly identical to Model.getAttributes except that it always inserts the primary key of the model (if the model has one) first. The other difference between this method and Model.getAttributes is that this method will callfield.type.serializeon each field value.Return value:
objectAll model attributes, ready to be serialized.
See also: Type.serialize
Get a string representation of this model.
Return value:
stringThe model's name and attributes as a string.
Update the
this.dirtyIDcache key of the model. This is called any time a field is marked as "dirty" on the model. ThedirtyIDproperty of a model is an instance of a CacheKey that is intended to be used for caching systems. The CacheKey instance can be used for a key into a WeakMap, which can cache things. Because this is updated to a new instance of a CacheKey any time any field on the model is marked as dirty, any cache for this model will be invalidated as soon as any field on the model is dirty.
- Associations
- Certifications
- Connection Binding
- Home
- Models
- Queries
- TypeScript
- Types Reference
-
namespace AsyncStore
- function getContextStore
- function getContextValue
- function runInContext
- function setContextValue
-
namespace Helpers
- function checkDefaultValueFlags
- function defaultValueFlags
- function getDefaultValueFlags
- property FLAG_LITERAL
- property FLAG_ON_INITIALIZE
- property FLAG_ON_INSERT
- property FLAG_ON_STORE
- property FLAG_ON_UPDATE
- property FLAG_REMOTE
-
namespace MiscUtils
- function collect
- function valueToDateTime
-
namespace ModelUtils
- function parseQualifiedName
-
namespace QueryUtils
- function generateQueryFromFilter
- function mergeFields
- function parseFilterFieldAndOperator
-
class AverageLiteral
- method static isAggregate
- method toString
-
class BigIntType
- property Default
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class BlobType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class BooleanType
- method castToType
- method isValidValue
- method static getDisplayName
- method toString
-
class CacheKey
- method constructor
- method valueOf
-
class CharType
- method castToType
- method isValidValue
- method static getDisplayName
- method toString
-
class ConnectionBase
- property _isMythixConnection
- property DefaultQueryGenerator
- property dialect
- property Literals
- method _averageLiteralToString
- method _bigintTypeToString
- method _blobTypeToString
- method _booleanTypeToString
- method _charTypeToString
- method _countLiteralToString
- method _datetimeTypeToString
- method _dateTypeToString
- method _distinctLiteralToString
- method _escape
- method _escapeID
- method _fieldLiteralToString
- method _getFromModelCache
- method _integerTypeToString
- method _maxLiteralToString
- method _minLiteralToString
- method _numericTypeToString
- method _realTypeToString
- method _setToModelCache
- method _stringTypeToString
- method _sumLiteralToString
- method _textTypeToString
- method _uuidV1TypeToString
- method _uuidV3TypeToString
- method _uuidV4TypeToString
- method _uuidV5TypeToString
- method _xidTypeToString
- method addColumn
- method addIndex
- method aggregate
- method alterColumn
- method alterTable
- method average
- method buildConnectionContext
- method bulkModelOperation
- method constructor
- method convertDateToDBTime
- method count
- method createContext
- method createQueryGenerator
- method createTable
- method createTables
- method destroy
- method destroyModels
- method dirtyFieldHelper
- method dropColumn
- method dropIndex
- method dropTable
- method dropTables
- method ensureAllModelsAreInstances
- method escape
- method escapeID
- method exists
- method finalizeQuery
- method findModelField
- method getContextValue
- method getDefaultFieldValue
- method getDefaultOrder
- method getField
- method getLockMode
- method getModel
- method getModels
- method getOptions
- method getQueryEngineClass
- method getQueryGenerator
- method insert
- method isStarted
- method literalToString
- method max
- method min
- method parseQualifiedName
- method pluck
- method prepareAllModelsAndSubModelsForOperation
- method prepareAllModelsForOperation
- method query
- method registerModel
- method registerModels
- method runSaveHooks
- method select
- method setContextValue
- method setPersisted
- method setQueryGenerator
- method splitModelAndSubModels
- method stackAssign
- method start
- method static getLiteralClassByName
- method static isConnection
- method static isConnectionClass
- method static Literal
- method stop
- method sum
- method toQueryEngine
- method transaction
- method truncate
- method typeToString
- method update
- method updateAll
- method upsert
-
class CountLiteral
- method static isAggregate
- method static isFieldRequired
- method toString
-
class DateTimeType
- property Default
- method castToType
- method constructor
- method deserialize
- method isValidValue
- method serialize
- method static getDisplayName
- method toString
-
class DateType
- property Default
- method castToType
- method constructor
- method deserialize
- method isValidValue
- method serialize
- method static getDisplayName
- method toString
-
class DistinctLiteral
- method toString
-
class Field
- property _isMythixField
- property allowNull
- property defaultValue
- property fieldName
- property get
- property index
- property primaryKey
- property set
- property type
- property unique
- property validate
- method clone
- method constructor
- method setModel
- method static isField
- method static isFieldClass
-
class FieldLiteral
- method toString
- class FieldScope
-
class ForeignKeyType
- method castToType
- method constructor
- method getOptions
- method getTargetField
- method getTargetFieldName
- method getTargetModel
- method getTargetModelName
- method initialize
- method isValidValue
- method parseOptionsAndCheckForErrors
- method static getDisplayName
- method static isForeignKey
- method toString
-
class IntegerType
- property Default
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class Literal
- method constructor
-
class LiteralBase
- property _isMythixLiteral
- method constructor
- method definitionToField
- method fullyQualifiedNameToDefinition
- method static isAggregate
- method static isLiteral
- method static isLiteralClass
- method static isLiteralType
- method toString
- method valueOf
-
class LiteralFieldBase
- method constructor
- method getField
- method getFullyQualifiedFieldName
- method static isFieldRequired
- method valueOf
-
class MaxLiteral
- method static isAggregate
- method toString
-
class MinLiteral
- method static isAggregate
- method toString
-
class Model
- property _isMythixModel
- method _castFieldValue
- method _constructField
- method _constructFields
- method _constructor
- method _getConnection
- method _getDirtyFields
- method _getFieldValue
- method _initializeFieldData
- method _initializeModelData
- method _setFieldValue
- method clearDirty
- method constructor
- method destroy
- method getAttributes
- method getConnection
- method getDataValue
- method getDirtyFields
- method getOptions
- method hasValidPrimaryKey
- method isDirty
- method isPersisted
- method onAfterCreate
- method onAfterSave
- method onAfterUpdate
- method onBeforeCreate
- method onBeforeSave
- method onBeforeUpdate
- method onValidate
- method reload
- method save
- method setAttributes
- method setDataValue
- method static _getConnection
- method static all
- method static bindConnection
- method static count
- method static create
- method static cursor
- method static defaultScope
- method static finalizeQuery
- method static first
- method static getConcreteFieldCount
- method static getContextValue
- method static getField
- method static getFields
- method static getForeignKeyFieldsMap
- method static getForeignKeysTargetField
- method static getForeignKeysTargetFieldNames
- method static getForeignKeysTargetModelNames
- method static getForeignKeysTargetModels
- method static getModel
- method static getModelContext
- method static getModelName
- method static getPluralModelName
- method static getPrimaryKeyField
- method static getPrimaryKeyFieldName
- method static getQueryEngine
- method static getQueryEngineClass
- method static getSingularName
- method static getSortedFields
- method static getTableName
- method static getUnscopedQueryEngine
- method static getWhereWithConnection
- method static hasField
- method static hasRemoteFieldValues
- method static initializeFields
- method static isForeignKeyTargetModel
- method static isModel
- method static isModelClass
- method static iterateFields
- method static last
- method static mergeFields
- method static pluck
- method static primaryKeyHasRemoteValue
- method static setContextValue
- method static toString
- method static updateModelContext
- method toJSON
- method toString
- method updateDirtyID
-
class ModelScope
- method _getField
- method AND
- method CROSS_JOIN
- method DISTINCT
- method EXISTS
- method Field
- method FULL_JOIN
- method GROUP_BY
- method HAVING
- method INNER_JOIN
- method JOIN
- method LEFT_JOIN
- method LIMIT
- method mergeFields
- method NOT
- method OFFSET
- method OR
- method ORDER
- method PROJECT
- method RIGHT_JOIN
-
class ModelType
- method fieldNameToOperationName
- method initialize
-
class ModelsType
- method fieldNameToOperationName
- method initialize
-
class NumericType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class ProxyClass
- property APPLY
- property AUTO_CALL
- property AUTO_CALL_CALLED
- property AUTO_CALL_CALLER
- property CALLABLE
- property CONSTRUCT
- property DEFINE_PROPERTY
- property DELETE_PROPERTY
- property GET
- property GET_OWN_PROPERTY_DESCRIPTOR
- property GET_PROTOTYPEOF
- property HAS
- property IS_EXTENSIBLE
- property MISSING
- property OWN_KEYS
- property PREVENT_EXTENSIONS
- property PROXY
- property SELF
- property SET
- property SET_PROTOTYPEOF
- property shouldSkipProxy
- property TARGET
- method ___autoCall
- method ___call
- method constructor
-
class QueryEngine
- method all
- method average
- method constructor
- method count
- method cursor
- method destroy
- method exists
- method finalizeQuery
- method first
- method getFieldScopeClass
- method getModelScopeClass
- method last
- method max
- method MERGE
- method min
- method Model
- method pluck
- method sum
- method toString
- method unscoped
- method updateAll
-
class QueryEngineBase
- method _fetchScope
- method _inheritContext
- method _newFieldScope
- method _newModelScope
- method _newQueryEngineScope
- method _pushOperationOntoStack
- method clone
- method constructor
- method filter
- method getAllModelsUsedInQuery
- method getConnection
- method getFieldScopeClass
- method getModel
- method getModelScopeClass
- method getOperationContext
- method getOperationStack
- method getQueryEngineClass
- method getQueryEngineScope
- method getQueryEngineScopeClass
- method getQueryID
- method isLastOperationCondition
- method isLastOperationControl
- method isModelUsedInQuery
- method logQueryOperations
- method map
- method queryHasConditions
- method queryHasJoins
- method static generateID
- method static getQueryOperationInfo
- method static isQuery
- method static isQueryOperationContext
- method walk
-
class QueryGeneratorBase
- method _averageLiteralToString
- method _countLiteralToString
- method _distinctLiteralToString
- method _fieldLiteralToString
- method _maxLiteralToString
- method _minLiteralToString
- method _sumLiteralToString
- method constructor
- method escape
- method escapeID
- method getConnection
- method getFieldDefaultValue
- method getIndexFieldsFromFieldIndex
- method setConnection
- method stackAssign
- method toConnectionString
-
class RealType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class SerializedType
- method castToType
- method constructor
- method deserialize
- method getOptions
- method initialize
- method isDirty
- method isValidValue
- method onSetFieldValue
- method serialize
- method static getDisplayName
- method toString
-
class StringType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class SumLiteral
- method static isAggregate
- method toString
-
class TextType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class Type
- property _isMythixFieldType
- property clone
- method castToType
- method clone
- method constructor
- method deserialize
- method exposeToModel
- method getDisplayName
- method getField
- method getModel
- method initialize
- method isDirty
- method isForeignKey
- method isRelational
- method isRemote
- method isValidValue
- method isVirtual
- method onSetFieldValue
- method serialize
- method setField
- method setModel
- method static instantiateType
- method static isSameType
- method static isType
- method static isTypeClass
- method static wrapConstructor
- method toConnectionType
-
class UUIDV1Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class UUIDV3Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class UUIDV4Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class UUIDV5Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class XIDType
- property Default
- method castToType
- method isValidValue
- method static getDisplayName