如何创建与 SailsJS 中另一个模型的对象单向关联的对象列表?
How to create a list of objects which are one-way associated with objects of another model in SailsJS?
我有模型 Playlist.js 和 User.js。我想在播放列表中有一个用户列表,可以回答对他们的评论。我不希望该属性出现在用户中。 (即单向关联)
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
我想找到一种方法来获得与用户有关联的用户列表?
将模型更改为集合:
users_who_can_answer_comments: {
collection: 'user'
}
我有模型 Playlist.js 和 User.js。我想在播放列表中有一个用户列表,可以回答对他们的评论。我不希望该属性出现在用户中。 (即单向关联)
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 我想找到一种方法来获得与用户有关联的用户列表?
将模型更改为集合:
users_who_can_answer_comments: {
collection: 'user'
}