我在Nodejs和sails上都很新.我正在实现一个类似于Twitter的服务器.在用户模型中,应该有2个字段:跟随者和跟随者,并且2个字段是模型"用户"本身的关联.
我的问题是当模型只有1个关联时,无论是跟随者还是跟随者,它都有效.但是,如果包括跟随者和跟随者,则会出现错误.
代码是这样的:
module.exports = {
attributes: {
alias: {
type:'string',
required: true,
primaryKey: true
},
pwd: {
type: 'string',
required: true
},
follower: {
collection: 'user',
via: 'alias'
},
following:{
collection: 'user',
via: 'alias'
}
}
Run Code Online (Sandbox Code Playgroud)
代码会导致这样的错误:
usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/references.js:115
throw new Error('Trying to associate a collection attribute to a model tha
^
Error: Trying to associate a collection attribute to a model that doesn't have a Foreign Key. user is trying to reference a foreign key in user
at References.findReference …Run Code Online (Sandbox Code Playgroud)