问题描述:

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.

相关阅读:
Top