Reputation: 159
I am new to sails js. I am using mongodb database. I have users
collection. I have created api using sails generate api users
it creates Users.js
and UsersController.js
files. I want to know that can we create another controller or model for the same collection?
I have created User_dummy.js
and User_dummyController.js
using same command given above. And copied the content of the file Users.js
into User_dummy.js
and UsersController.js
file into User_dummyController.js
. But it doesn't work.
Its giving me following error :
Trying to associate a collection attribute to a model that doesn't have a Foreign Key.
I want to make two copies of both model and controller for users
collection. Is there any solution or is there any way to create two controller or model.
Upvotes: 0
Views: 243
Reputation: 3536
You should be able to use the tableName
model setting (see documentation) to have a shared collection for two or more models.
Users.js/User_dummy.js:
module.exports = {
tableName: 'users',
attributes: {
}
};
Upvotes: 1