Ignore fields

Hiding fields from storing, serialization and response


Fields which decorate with @Ignore() will not be present during the storage procedure, response to client and serialization ( JSON.stringify() ).


export class YourModel extends ModelAbstract{
    public id:string;
    public name:string;
    public shouldGenerateId:boolean;
    protected saveEmitter(options?: any): Promise<any> {
            this.id = StringUtils.generateId();
        return rp({
            method: 'POST',
            uri: `/${this.getModelName()}`,
            body: JSON.stringify(this) // Won't contain `shouldGenerateId` property


The addFieldsToIgnore instance function allow you to apply the ignore functionality without decorators, each field added to "ignored" will automatically be hidden.


The removeFieldsFromIgnore instance function allow you to prohibit hiding fields using hideIgnoredFields() . The passed fields names can be either a field that decorated with Ignore() or fields which add with addFieldsToIgnore().


The hideIgnoredFields()instance function will hide all of the fields which decorated with Ignored() or added by addFieldsToIgnore.


By default, all ignored fields won't present during serialization and response, you can toggle this logic off by calling showIgnoredFields() instance function.

Last updated