- Development Mode
- File System
- Data Types and Attributes
- Instance and Class Methods
- Model Configuration
Instance and Class Methods
You can attach instance methods to a model which will be available on any record returned from a query. These are defined as functions in your model attributes.
toObject() method will return the currently set model values only, without any of the instance methods attached. Useful if you want to change or remove values before sending to the client.
However we provide an even easier way to filter values before returning to the client by allowing you to override the
toJSON() method in your model.
Example of filtering a password in your model definition:
“Class” methods are functions available at the top level of a model. They can be called anytime after you get a model instance.
These are useful if you would like to keep model logic in the model and have reusable functions available.
// example.js - just an example model