Whenever Waterline retrieves a record, it checks whether or not the record’s model has a
customToJSON method defined, and if so, adds it to the record as its
toJSON property. It is not intended to be called directly in your code, but instead is used automatically when a record is serialized via a call to
res.json() method in particular stringifies objects in this way.
customToJSON is defined for a model, the
.toJSON() method will be added to records retrieved via
.stream(), as well as those retrieved by setting the
fetch meta key to
true in calls to
.destroy(). If any child records are attached via
.populate(), and the corresponding models have
customToJSON methods, then the child records will also have
.toJSON() functions attached.
See the customToJSON documentation for more info on how to customize the way your records are presented.