Skip to content
Wyatt Greenway edited this page Aug 25, 2022 · 49 revisions

class 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.


static property Model::_isMythixModel: boolean = true

This property assists with type checking.


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?: Connection

    An 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

Notes:

  • 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.

static method Model::isModel(value: any)

Check to see if the provided value is an instance of a Mythix ORM Model. Unlike 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 true if the provided value is an instanceof Model, or if the values constructor property has a truthy _isMythixModel property.

Arguments:

  • value: any

    Value to check.

Return value: boolean


static method Model::isModelClass(value: Function)

Use this method to check if a class is a Mythix ORM model. It will return true if the provided value is a class that inherits from Model, or if the provided value has an attribute named _isMythixModel that is truthy.

Arguments:

  • value: Function

    Value to check.

Return value: boolean


static method Model::toString(showFields?: boolean)

Like everywhere in Javascript, we can call .toString() to a get a string representation of our Model class. The optional showFields argument, if true, will list the models fields as well. Without the showFields argument, the model name alone will be returned as a string.

Arguments:

  • showFields?: boolean

    If true, then list the models fields.

Return value: string



Clone this wiki locally