Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sails.js model acces by string name

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'});
like image 926
Martin Avatar asked Oct 19 '14 05:10

Martin


1 Answers

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.

like image 172
abeja Avatar answered Nov 03 '22 21:11

abeja