Fribu Fribu - 13 days ago 10
Node.js Question

Sailsjs: dynamic tableName in model

I am building my first sailsjs and nodejs application, and it great :)

My situation, I have about 100 tables with the same stucture, I would like to decide "on the fly" which table to load.

my first thought was use somehow a dynamic class names. But I dont know how to do this with nodejs, maybe some one have an idea.

So I would create 100 "modelName".js files in my models folder.

I can use this in browser

window["fileName"].find()....


But I don't have any window object in nodejs

Second idea was to pass the tableName to the model, the problem is, I have to reinit the model, don't know how.

Any solutions?

Answer

Found a solution

var modelName = req.param('p');
this[modelName].find()...