2016-11-02 9 views
0

私はモデルループバックで結合が動作しないのはなぜですか?

{ 
    "name": "user", 
    "plural": "users", 
    "base": "User", 
    "relations": { 
    "roles": { 
     "type": "hasMany", 
     "model": "Role", 
     "foreignKey": "principalId", 
     "through": "RoleMapping" 
    } 
    }, 

を継承したとフックを作成し、successfulyデシベル(モンゴ)に追加したユーザー

UserModel.afterRemote('create', (context, user, next) => { 
     let body = context.req.body; 
     if (!body.hasOwnProperty('roleId')) { 
      next(); 
     } 
     Role.findById(body.roleId) 
      .then(role => { 
      if (!role){ 
       next(); 
      } 
      return user.roles.add(role); 
      }) 
      .then(roleMapping => { 
      next(); 
      }); 
     }); 

とレコードとの役割を保存するための、しかし要求が

/api/users?access_token={}[include]=roles 

レコードを取得しながら、参加していない、なぜですか?

答えて

-1

あなたのクエリ文字列をインクルードフィルタは

/api/users?access_token={}&filter[include]=roles

include filter

する必要があります含める 間違っています
関連する問題