Tag: sails.js waterline

更新sailsjs模型afterCreate挂钩中的undefined

在我的sailsjs应用程序中,我试图添加一个默认的头像为我的用户创build用户后,所以我在models/User.js这个afterCreate挂钩: var User = { // … attributes: { avatar: { model: 'Image' }, // … }, afterCreate: function(user, next){ var url = sails.config.s3 + "/" + sails.config.default_avatar; sails.log.info(user); // This displays the proper user var data = { url: url, isAvatar: true, user: user.id }; Image.create(data) .exec( function (err, image) { sails.log.info(image); // This […]

Sailsjs Mysql ORM在同一个表字段上进行多个查询

我使用的风帆V 0.10.5和最新的风帆 – MySQL的 我有一个餐厅过滤系统 Venue.find().populate('comments', { deleted: false }).where({ restaurant_services: {contains: '"delivery":1'}, restaurant_services: {contains: '"takeout":1'}, restaurant_specialties: {contains: '"breakfast":1'} }) 现在问题是当我从客户端获取数据时,我不知道用户为restaurat_servicesselect了多less项目,所以显然我必须为.where()函数创build一个dynamicJSON对象 问题是,我不能这样做 var searchObj = {}; searchObj['restaurant_specialties'] = {contains: '"breakfast":1'}; searchObj['restaurant_specialties'] = {contains: '"breakfast":1'}; 所以你可能会看到之前的值设置被第二次replace, 任何帮助将不胜感激聪明的人在这里,但不工作 Model.find({ name: { 'contains' : ['Walter', 'Skyler'] } });

在左连接中不能保留第一个表的id

我正在使用帆水线ORM,我有三个表在我的模型层 1- s_class attributes: { c_title:{ type:'string', required: true }, sec:{ collection:'s_section', via:"cls" }, s_session:{ model:'s_session', columnName:'session' } } 2- s_section attributes: { sec_title:{ type:'string' }, sec_priority:{ type:'integer', required: true }, cls:{ collection:'s_class', via:"sec" } } 3- s_form attributes: { studentName:{ type:'string' }, s_class:{ columnName:'s_class', model:'s_class' }, s_section:{ columnName:'s_section', model:'s_section' } } 我将课程和课程分配给学生,并保存在s_form表格中。当我编写一个查询来获得学生的logging时,他的课程和部分是这样的: s_form.query("SELECT * […]

获取与模型相关的所有收集logging

// Note model attributes: { // Relations notebook: { model: 'Notebook' }, } 和 // Notebook attributes: { // Relations owner: { model: 'User' }, notes: { collection: 'Note', via: 'notebook' } } 在控制器中: Notebook.findOne({owner: user.id}, function (err, notebook) { if (err || !notebook) { return res.serverError(err); } // –> until here it goes all […]

帆:如何避免同时上传一个文件的同名

我在sails.js.上传文件到我的本地path。 但问题是当我再次上传一个相同的文件意味着它将覆盖现有的文件。 var uploadFile= req.file('SourceFileImport'); uploadFile.upload ({ // don't allow the total upload size to exceed ~10MB maxBytes: 10000000,saveAs: function(uploadFile, cb) {cb(null, uploadFile.filename); },dirname: '../../assets/uploads' },function whenDone(err, uploadedFiles) { if (err) { console.log("error"); return res.negotiate(err); } // If no files were uploaded, respond with an error. if (uploadedFiles.length === 0) { return res.badRequest('No file was […]

风帆政策 – 通过协会进行search

比方说,我有一个模型用户 ,可以有多个房屋 。 这些房子可以有多个停车位 ,然后可以有多辆汽车或自行车 用户>房屋>停车位> [汽车,自行车] 如何检查汽车是否与用户有关? 比方说,当一个用户(当前login的用户)想要编辑或删除一辆车时,我想检查他是否是该车的主人。 当他想要在房子或停车位上进行操作时也是如此。 由于模型用户并不直接与模型车或停车位相关联,因此检查对象是否与用户有关的最佳方法是什么? 有什么方法可以查找“一级协会”? 提前致谢 丹尼斯

Sails.js水线查询通过关联

我正在开发和应用Sails.js并使用Waterline orm for db。 我正在开发function为用户做朋友请求和其他类似的请求。 我有以下URequest模型: module.exports = { attributes: { owner: { model: 'Person' }, people: { collection: 'Person' }, answers: { collection: 'URequestAnswer' }, action: { type: 'json' //TODO: Consider alternative more schema consistent approach. } } }; 基本上所有者是与发出请求的人的联系,并且人是与请求被指示的所有人的一对多联系。 到目前为止罚款。 现在我想有一个控制器返回所有请求,其中某个用户参与意味着所有的请求,其中用户是在所有者领域或在人。 我如何做查询就像“给我所有的行与人P的关联”? 换句话说,我如何知道哪个URequest模型与某个Person有关联? 我尝试了这样的事情: getRequests: function (req, res) { var personId = req.param('personId'); […]

Sails.jsfind错误

大家好! 我正在用postgres来开发风帆。 我有一个与轨道集合的播放列表。 像那样 : Playlist = { tracks: { collection: track } } 我试图提出这样的要求: Playlist.find({tracks: 1}).exec(…) 要获取所有轨道ID为1的播放列表! 但是sails return =>详细信息:错误:列playlist.tracks不存在。 不明白,因为waterline创build了一个名为“playlist_tracks__track_tracks_track”的表和所有的关系。 有人可以帮助我吗?

组水线 – 白天的结果

我想弄清楚如何打印日志文件的概述。 为此,我希望每天都要返回一个列表。 module.exports = { overview: function(req, res) { var query = streamlog.find({ groupBy: ['created'], max: ['ogg'] }); query.exec(function (err, matchingRecords) { res.ok(matchingRecords); }); }, }; 这只能解决部分问题,因为使用上面的groupBy时,仅以秒/分钟/小时为单位的项目不相同。 我正在使用mongo,如果这可能有帮助

无法将variables作为标准发送给waterline查询

我build立的查询条件如下,我把它存储在一个名为“选项” if (typeof cb.parametre.categorie !== "undefined") { if(typeof options !== "undefined") { options =options+ '{categorie: ' + cb.parametre.categorie + '}'; }else { options = '{categorie: ' + cb.parametre.categorie + '}'; } } if (typeof cb.parametre.localisation !== "undefined") { if(typeof options !== "undefined") { options=options+',{nomVille:'+cb.parametre.localisation.address_components[0].long_name+'}'; } else { options='{nomVille:'+cb.parametre.localisation.address_components[0].long_name+'}'; } } if(cb.parametre.motclef) { if(typeof options !== […]