1
모델이 입니다. Playlist.js 및 User.js입니다. Playlist에있는 댓글 목록에 사용자의 의견을달라고 요청할 수 있습니다. 사용자에게 표시되는 속성을 원하지 않습니다. (즉, 편도-협회)SailsJS에서 다른 모델의 개체와 단방향으로 연결된 개체 목록을 만드는 방법은 무엇입니까?
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'
}
}
};
항해 문서는 일대일 매핑에 대한 단방향 관계를 언급 한 - http://sailsjs.org/documentation/concepts/models-and-orm/associations/one-way-association 사용자와의 연관성이있는 사용자 목록을 얻는 방법을 찾고 싶습니다. 컬렉션에
그래서 그것은 단지처럼 일대, 사용자 측면에서 재생 목록을 언급하지 않고? –
예, 정확히;) –
'via'및 'through'속성을 사용하고 연관 모델을 만들 수도 있습니다. 그렇지 않으면 테이블 이름이 매우 길어집니다 ('playlist_users_who_can_answer_comments__user_users_who_can_answer_comments_user'). 그러면 오류가 발생합니다. '오류 : 오류 (E_UNKNOWN) :: 예기치 않은 오류가 발생했습니다. : ER_TOO_LONG_IDENT : 'playlist_users_who_can_answer_comments__user_users_who_can_answer_comments_user'식별자 이름이 너무 깁니다. ' –