Reputation: 581
I am trying to add Laravel-like Mass Assign to my Sails 0.12 application.
So far I have done:
Add method secureUpdate
to config\models.js
:
console.log(this);
var self = this;
var modelName = self.adapter.identity.charAt(0).toUpperCase() + self.adapter.identity.slice(1);
I am trying to get the calling model name, just like in seed
method in this gist(for seeding data): https://gist.github.com/juanpasolano/5c7596d8629eeeb8debd#file-config-models-js
But the value of this
is diffirent, with no adapter object(undefined)
I do not understand why the value of this
is not the same. Could you help me out?
Upvotes: 0
Views: 114
Reputation: 1255
I write the answer here just for others who may have the same problem in the future :
The this
is undefined
because you are defining the method as an arrow function, you have to use a function expression, from MDN :
An arrow function expression has a shorter syntax than a function expression and does not have its own this, arguments, super, or new.target. These function expressions are best suited for non-method functions, and they cannot be used as constructors.
Upvotes: 1