Class: Registry

Registry()

new Registry()

Define and reference `Models` and `DataSources`.
Source:

Methods

configureModel(ModelCtor)

Alter an existing Model class.
Parameters:
Name Type Description
ModelCtor Model The model constructor to alter.
Properties:
Name Type Attributes Description
dataSource DataSource Attach the model to a dataSource.
relations Object <optional>
Model relations to add/update.
Source:

createDataSource(name)

Create a data source with passing the provided options to the connector.
Parameters:
Name Type Description
name String Optional name.
Properties:
Name Type Attributes Description
connector Object LoopBack connector.
* * <optional>
Other connector properties. See the relevant connector documentation.
Source:

createModel(name, properties, options)

Create a named vanilla JavaScript class constructor with an attached set of properties and options. This function comes with two variants: * `loopback.createModel(name, properties, options)` * `loopback.createModel(config)` In the second variant, the parameters `name`, `properties` and `options` are provided in the config object. Any additional config entries are interpreted as `options`, i.e. the following two configs are identical: ```js { name: 'Customer', base: 'User' } { name: 'Customer', options: { base: 'User' } } ``` **Example** Create an `Author` model using the three-parameter variant: ```js loopback.createModel( 'Author', { firstName: 'string', lastName: 'string' }, { relations: { books: { model: 'Book', type: 'hasAndBelongsToMany' } } } ); ``` Create the same model using a config object: ```js loopback.createModel({ name: 'Author', properties: { firstName: 'string', lastName: 'string' }, relations: { books: { model: 'Book', type: 'hasAndBelongsToMany' } } }); ```
Parameters:
Name Type Description
name String Unique name.
properties Object
options Object (optional)
Source:

findModel(modelOrName) → {Model}

Look up a model class by name from all models created by `loopback.createModel()`
Parameters:
Name Type Description
modelOrName String | function The model name or a `Model` constructor.
Source:
Returns:
The model class
Type
Model

getModel(modelOrName) → {Model}

Look up a model class by name from all models created by `loopback.createModel()`. **Throw an error when no such model exists.**
Parameters:
Name Type Description
modelOrName String The model name or a `Model` constructor.
Source:
Returns:
The model class
Type
Model

getModelByType(modelType) → {Model}

Look up a model class by the base model class. The method can be used by LoopBack to find configured models in models.json over the base model.
Parameters:
Name Type Description
modelType Model The base model class
Source:
Returns:
The subclass if found or the base class
Type
Model

memory(nameopt)

Get an in-memory data source. Use one if it already exists.
Parameters:
Name Type Attributes Description
name String <optional>
The name of the data source. If not provided, the `'default'` is used.
Source: