我有模型 Playlist.js 和 User.js 。我想在播放列表中有一个用户列表,可以回答对它们的评论。我不希望该属性出现在User中。 (即单向关联)
Playlist.js
module.exports = {
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey:
},
name: {
type: 'string',
size: 128,
required: true
},
// many to many relationship with role
roles_with_access: {
collection: 'role',
via: 'playlist',
through: 'rolehasplaylist'
},
// THIS ATTRIBUTE ASSOCIATE WITH ONE USER
// BUT INSTEAD OF THAT I WANT A LIST OF USERS
users_who_can_answer_comments: {
model: 'user'
}
}
};
user.js的
module.exports = {
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true,
},
name: {
type: 'string',
size: 128,
required: true
},
email: {
type: 'email',
required: true,
unique: true
},
adminRole: {
model: 'role'
}
}
};
Sails文档提到仅针对一对一映射的单向关联 - http://sailsjs.org/documentation/concepts/models-and-orm/associations/one-way-association 我想找到一种方法来获得与用户关联的用户列表?
答案 0 :(得分:1)
将模型更改为集合:
users_who_can_answer_comments: {
collection: 'user'
}