Question

How do i Find all registers of one only column in sails

my model is:

models/Blog.js

module.exports = {
    schema: true,
    attributes: {
        title:'string',
        content:{
            type:'string',
            required: true
        }
    }
};

my controller: controllers/BlogController.js

module.exports = {

    index: function (req, res) {

        Blog.find()
        .exec(function (err, content) {
          if (err) {
            res.send(400);
          } else {
            res.view({OnlyContent:content}); // Only view all Content ?
          }
        });

    },
_config: {}
};
Was it helpful?

Solution

To only send the data of content to your client, you need to loop through the returned array of blogs and filter out the content.

index: function (req, res) {

    Blog.find().exec(function (err, allBlogs) {
        if (err) { 
            res.send(400);
        } else {
            var allContent = [];
            allBlogs.forEach(function (blog) {
                allContent.push(blog.content);
            })

            res.view({
                OnlyContent: allContent
            });
        }
    });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top