javascript - Getting old records from Sails Models -
im trying build complete chat sails.js websockets im facing troubles.
i succeed send , new messages when new client connect chat new client get older messages (like 20 last messages sent in chat).
message.js (model)
module.exports = { attributes: { name : { type: 'string' }, message : { type: 'string' } } };
messagecontroller.js (controller)
module.exports = { new: function(req, res) { var data = { name: req.param('name'), message: req.param('message'), }; message.create(data).exec(function created(err, message){ message.publishcreate({id: message.id, name: message.name, message: message.message}); }); }, subscribe: function(req, res) { message.watch(req); } };
i had idea using "find" function on model not conclusive.
i hope im not missing big sails possibilities !
need :) !
message.find({sort: 'createdat asc'}).exec(function(err, results) { //results array of messages });
http://sailsjs.org/documentation/concepts/models-and-orm/query-language
Comments
Post a Comment