Sails.js model availability by string name

Is there a way to access the models in the sails by the name contained in the 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'});
+4
source share
1 answer

All model references are stored in the globally accessible sails.models object . You can access any of your models using literal array notation [].

var model = sails.models['users'];
model.create({name: 'martin'});

The same rule applies to controllers and services.

+6
source

All Articles