Is there any way to access models in sails by its name being contained in a string?
for example, if I want to create a user, instead of doing
User.create({name: 'martin'});
I need to do something like
sails['User'].create({name: 'martin'});
All references to models are stored in globally accessible object sails.models. You can access any of your model using the array literal notation [].
var model = sails.models['users'];
model.create({name: 'martin'});
The same rule applies to controllers and services.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With