I am using mongodb and I have installed sails-mongodb. I can access mongodb from controller(sails.js).
Issue 1: I have created a model using sails command, but I dont know how to create function for insert, edit, list and delete.
How to load the model into controller?
How to call the model functions from controller?
Issue 2: In this following controller, I store the values I intend to user in my view in 'data'. I dont know how to create db functions in model section so I have fetched some data from database using find function, but how do I assign that category values into data.list ?
module.exports = {
index: function (req, res) {
var data = new Object();
data.title = "Page title";
data.meta_keywords = "k1,k2,k3";
data.meta_description = "sample data";
data.lists = "";
Category.find().done(function(err, category) {
data.lists = category;
});
bredcrumbs = new Array();
bredcrumbs[0] = {'text':'Home','link':'Link','active':false};
res.view("pages/home",data);
},
_config: {}
};
I have created one model file with named category.js
tableName: 'category',
module.exports = {
attributes: {
name: {
type: 'STRING',
required: true
},
keyword: {
type: 'STRING',
required: true
},
image: 'STRING',
sort_order: 'INTEGER',
date_added: 'DATETIME',
status: 'BOOLEAN'
},
toJSON: function() {
var obj = this.toObject();
return obj;
}
};