anatidae
anatidae

Reputation: 21

Is it possible to get model definition in callback override in sails.js?

I am working on something similar to Can I specify a lifecycle callback that fires for all waterline models in sails?.

I'd like to be able to reference the model definition in the callback, but only the attributes and id are currently sent to the afterUpdate. Is there a way to determine which model I'm working with, other than adding 'type' as an attribute?

Upvotes: 1

Views: 164

Answers (1)

anatidae
anatidae

Reputation: 21

Correct scoping plus this will work in config/models.js.

module.exports.models = {

    attributes: { . . .},

    afterUpdate: function (model) {
        console.log(this.identity);  //model name that triggered callback
        console.log(this.definition); //model definition

        //logic . . .
    }
};

Upvotes: 1

Related Questions