# Providers

The provider class needs to extend the Provider class. This class also requires a basic set of tools to make it easier for developers to work with your provider. These tools would look something like this:

import { Provider } from '../core/provider';
import { YourModelType } from '../core/types';
import { fetchModel, YourModel } from '../schema/models';

export class YourProvider extends Provider 
{
    private model: YourModelType;

    constructor() 
    {
        super();
        this.model = fetchModel<YourModel>('model_key');
    }

    public static get model() 
    {
        return fetchModel<YourModel>('model_key');
    }
}

The constructor makes it easy for you to use the model within the class. The getter is used when you want to populate a database call automatically and don't want to type the whole complex line each time you populate the specific property.

Example of populating on a database call:

let result = await this.someOtherModel.find(query)
                                      .populate('property', YourProvider.model)
                                      .exec();

As you can see in another provider somewhere we could need to have a instance of your model to populate a certain property that relates to your model. Using the model getter, we get that instance very easily and legibly.

Last Updated: 7/15/2022, 3:12:37 PM