Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Sailsjs: dynamic tableName in model

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


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?

Problem courtesy of: Fribu


Found a solution

var modelName = req.param('p');
Solution courtesy of: Fribu


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Sailsjs: dynamic tableName in model


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription