Members
(static) dependencies :Array.<string>
- Source:
Class dependencies:
['app', 'db.model', 'faker']
.
Methods
get(name)
- Source:
Get model factory instance by name.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The model factory name. |
Returns:
The model factory instance.
- Type
- database.Factory
make(model, parametersopt, timesopt)
- Source:
Make a model with attributes from its associated factory.
Example
factory.make('user'); // User { name: "John Smith", email: "john.smith@example.com" }
factory.make('user', { name: 'John Doe' }); // User { name: "John Doe", email: "john.smith@example.com" }
factory.make('user', 3); // Collection { [User { name: 'John Smith', email: 'john.smith@example.com }, User { ... }, User { ... }] }
factory.make('user, { name: 'John Doe' }, 2); // Collection { []User { name: 'John Doe', email: 'johm.smith@example.com' }, User { ... }] }
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
model |
string | The model name. | ||
parameters |
object.<string, *> | number |
<optional> |
{}
|
The parameters to put into the model manually, overwriting matching factoried values. Can also be the times if no parameter are given. |
times |
number |
<optional> |
1
|
The quantity of models that needed to be factoried. Minimum 1 model is required. |
Returns:
Either a single Model instance or a Model Collection instance, containing N times the requested model.
- Type
- Model | Collection
register(factory, modelopt)
- Source:
Register factory for a given model.
If the model name is not provided, it will be taken from the factory instance.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
factory |
database.Factory | The factory class. | ||
model |
string | null |
<optional> |
null
|
The model name. If no value is provided, the factory model will be taken. |
Returns:
The factory service instance.