2016-09-23 14 views
1

私はモデルがです。Playlist.jsUser.jsです。プレイリストにユーザーのリストを入れて、そのプレイヤーのコメントに答えることができます。私はその属性をユーザーに表示したくありません。 (つまり、一方向アソシエーション)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 ユーザーとの関連付けを持つユーザーの一覧を表示する方法を探したいですか?コレクションに

答えて

1

変更モデル:

users_who_can_answer_comments: { 
    collection: 'user' 
} 
+0

だからそれはユーザ側からプレイリストに言及せず、ただ1対多のようなものですか? –

+0

はい、まあ;) –

+0

私は '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'の識別子の名前が長すぎます –