[英]Getting error: Must specify an `id` when calling `Model.room(id)` with Sails.js Pub/Sub
I'm trying to use pub/sub methods and I get spammed with this error: 我正在尝试使用pub / sub方法,但收到此错误的垃圾邮件:
error: Must specify an `id` when calling `Model.room(id)`
My Model looks like this: 我的模型如下所示:
module.exports = {
tableName: 'accounts',
autoPk: false,
attributes: {
'id': {
type: 'INTEGER',
primaryKey: true,
columnName: 'id'
},
'alias': {
type: 'STRING',
required: true
}
};
and then my controller method: 然后我的控制器方法:
'subscribe': function(req, res) {
Account.find({'select': ['steam_id', 'online']})
.then(function(users) {
Account.subscribe(req.socket, users);
})
.catch(function(err) {
console.log(err);
});
}
and finally, my client-side js subscribe: 最后,我的客户端js订阅:
socket.on('connect', function connectedToSockets() {
console.log('Subscribing');
socket.get('/friends/subscribe');
socket.get('/user/subscribe');
});
I cannot for the life of me, figure out why I am getting literally spammed by this error, all the fixes say to set a PrimaryKey on a column, 我无法一生,弄清楚为什么我会从字面上被这个错误所困扰,所有修复方法都说要在列上设置PrimaryKey,
I'm using sails-mysql
adapter 我正在使用
sails-mysql
适配器
Thanks! 谢谢!
So to anybody that has this problem, I figured it out: 因此,对于有此问题的任何人,我都可以理解:
I wasn't returning the ID from the query under subscribing, so when I added ID as well the error goes away, I guess it just need the ID for some reference. 我不是在订阅下从查询中返回ID,所以当我添加ID时,错误也消失了,我猜想它只需要ID供参考。
'subscribe': function(req, res) {
Account.find({'select': ['id', 'steam_id', 'online']})
.then(function(users) {
Account.subscribe(req.socket, users);
})
.catch(function(err) {
console.log(err);
});
}
This fixed it, adding id 固定它,添加id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.