我有模型 Playlist.js 和 User.js。我希望在播放列表中有一个可以回答对他们的评论的用户列表。我不希望该属性出现在用户中。 (即单向关联)
播放列表.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'
}
}
};
用户.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 我想找到一种方法来获得与用户关联的用户列表?
最佳答案
将模型更改为集合:
users_who_can_answer_comments: {
collection: 'user'
}
关于javascript - 如何在 SailsJS 中创建与另一个模型的对象单向关联的对象列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39653248/